Advertisement
Advertisement
| 06.04.2008 at 06:25PM PDT, ID: 23458904 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: |
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.IO
Server Module
_____________
Const portNo As Integer = 2700
Const BUFFER_SIZE As Integer = 10
'Dim listener As New TcpListener(localAdd, portNo)
Dim listener As New TcpListener(portNo)
listener.Start()
Console.WriteLine("Listening...")
Dim tcpClient As TcpClient = listener.AcceptTcpClient()
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim bytesToRead(tcpClient.ReceiveBufferSize) As Byte
Dim numBytesRead, j As Integer
'---read incoming stream and writing the bytes to file
Const FILE_NAME = "c:\test_TCP_server\received.jpg"
Dim fs As System.IO.FileStream
fs = New FileStream(FILE_NAME, FileMode.CreateNew, FileAccess.Write)
Do
numBytesRead = NWStream.Read(bytesToRead, 0, BUFFER_SIZE)
fs.Write(bytesToRead, 0, numBytesRead)
Loop Until Not NWStream.DataAvailable
fs.Close()
tcpClient.Close()
listener.Stop()
MsgBox("received")
Client Module
_______________
Const portNo = 2700
Const FILE_NAME = "c:\meter_pictures\c1m2.jpg"
Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect("zserver.i989.net", portNo)
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim fs As FileStream
Dim br As BinaryReader
Dim numBytesRead As Integer
fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
br = New BinaryReader(fs)
Dim bytesToSend(br.BaseStream.Length) As Byte
numBytesRead = fs.Read(bytesToSend, 0, bytesToSend.Length)
NWStream.Write(bytesToSend, 0, numBytesRead)
MsgBox("sent!!")
fs.Close()
tcpClient.Close()
|