G
Guest
Hi,
I'm writing a client/server application in which the client send a series of
screenshots to the server to be saved using the tcpclient.
in most cases the first screenshot is transmitted ok and arrives at the
server but from after that i only a couple of KB from the start of the file
which cases the picture to display only the very top (of the screen).
All the pictures are saved at the client side before sent to the server and
they are always good and "full", so the problems seem to be from the
transmition part or after that.
please help ...
****** Server Code:
Const portNo As Integer = 8080
Dim localAdd As System.Net.IPAddress = System.Net.IPAddress.Any
Dim listener As New TcpListener(localAdd, portNo)
listener.Start()
Dim tcpClient As TcpClient
tcpClient = listener.AcceptTcpClient()
tcpClient.ReceiveBufferSize = 400000
Dim lingerOption As New LingerOption(True, 10)
tcpClient.LingerState = lingerOption
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim bytesToRead(200000) As Byte
Dim numBytesRead As Integer = 0
'---read incoming stream
If NWStream.CanRead Then
Do
numBytesRead = numBytesRead + NWStream.Read(bytesToRead,
numBytesRead, tcpClient.ReceiveBufferSize)
Loop While NWStream.DataAvailable
NWStream.Close()
End If
Dim FileName = DateTimeForFile() & ".jpg"
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(FileName,
System.IO.FileMode.Create, _
System.IO.FileAccess.Write)
fs.Write(bytesToRead, 0, numBytesRead)
fs.Close()
MsgBox(numBytesRead)
tcpClient.Close()
listener.Stop()
****** Client Code:
Dim FileName = DateTimeForFile() & ".jpg"
< Code to save the screenshot on the client>
Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect(Me.TextBox_Server.Text, portNo)
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim fs As FileStream
fs = New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim bytesToSend(fs.Length) As Byte
Dim numBytesRead As Integer = fs.Read(bytesToSend, 0,
bytesToSend.Length)
fs.Close()
NWStream.Write(bytesToSend, 0, numBytesRead)
tcpClient.Close()
I'm writing a client/server application in which the client send a series of
screenshots to the server to be saved using the tcpclient.
in most cases the first screenshot is transmitted ok and arrives at the
server but from after that i only a couple of KB from the start of the file
which cases the picture to display only the very top (of the screen).
All the pictures are saved at the client side before sent to the server and
they are always good and "full", so the problems seem to be from the
transmition part or after that.
please help ...
****** Server Code:
Const portNo As Integer = 8080
Dim localAdd As System.Net.IPAddress = System.Net.IPAddress.Any
Dim listener As New TcpListener(localAdd, portNo)
listener.Start()
Dim tcpClient As TcpClient
tcpClient = listener.AcceptTcpClient()
tcpClient.ReceiveBufferSize = 400000
Dim lingerOption As New LingerOption(True, 10)
tcpClient.LingerState = lingerOption
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim bytesToRead(200000) As Byte
Dim numBytesRead As Integer = 0
'---read incoming stream
If NWStream.CanRead Then
Do
numBytesRead = numBytesRead + NWStream.Read(bytesToRead,
numBytesRead, tcpClient.ReceiveBufferSize)
Loop While NWStream.DataAvailable
NWStream.Close()
End If
Dim FileName = DateTimeForFile() & ".jpg"
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(FileName,
System.IO.FileMode.Create, _
System.IO.FileAccess.Write)
fs.Write(bytesToRead, 0, numBytesRead)
fs.Close()
MsgBox(numBytesRead)
tcpClient.Close()
listener.Stop()
****** Client Code:
Dim FileName = DateTimeForFile() & ".jpg"
< Code to save the screenshot on the client>
Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect(Me.TextBox_Server.Text, portNo)
Dim NWStream As NetworkStream = tcpClient.GetStream
Dim fs As FileStream
fs = New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim bytesToSend(fs.Length) As Byte
Dim numBytesRead As Integer = fs.Read(bytesToSend, 0,
bytesToSend.Length)
fs.Close()
NWStream.Write(bytesToSend, 0, numBytesRead)
tcpClient.Close()