I have two application which one is server and the other one is client written in VB.net. both of them are running on same machine ( using 127.0.0.1 ) client only sends 5 bytes data to server for example: "farid" but the sever app which has TCP listener receives a huge data with length of 65534 bytes. I tried to print the received data and it printed "farid" whith lots of empty spaces in front of it I am sure that the TCP client sends the right data, but I have no idea what happens to the data when listener receives it.
Asked
Active
Viewed 549 times
0
-
3Can you post some code to show what your client and server does. – Lotok May 08 '13 at 18:32
-
TCP is heavy... doesn't quite account for your current size, but... http://stackoverflow.com/questions/3613989/what-of-traffic-is-network-overhead-on-top-of-http-s-requests – FlavorScape May 08 '13 at 18:42
-
What protocol are you using over the sockets? Can you post a sample of the data your sending? – Kyght May 08 '13 at 18:46
-
I am testing this code, sever code: http://www.java-samples.com/showtutorial.php?tutorialid=1071 client code: http://www.java-samples.com/showtutorial.php?tutorialid=1070 – Farid Fereidooni May 08 '13 at 18:53
-
What your debugging the server, what is the value of the clientSocket.ReceiveBufferSize, is it 65534 bytes or have you read 65534 bytes of data or both. – Kyght May 08 '13 at 19:06
-
my buffer size is 10024 but it reads 65534 bytes while the client sends 5 byte. – Farid Fereidooni May 08 '13 at 19:31
1 Answers
1
The tutorial you were using has some horrible practices and mistakes in it... =\
The receive loop in getMessage() should look more like:
Private Sub getMessage()
Dim inStream(10024) As Byte
serverStream = clientSocket.GetStream()
While True
Dim bytesRead As Integer = serverStream.Read(inStream, 0, inStream.Length)
readData = System.Text.Encoding.ASCII.GetString(inStream, 0, bytesRead)
msg()
End While
End Sub
*Using the global string "readData" is a pretty bad design though!
You should read my article here closely: A Peer-To-Peer LAN Chat Application in Visual Basic.Net using TcpClient and TcpListener

Idle_Mind
- 38,363
- 3
- 29
- 40