Click here to Skip to main content
15,745,509 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a TCP-Server installed on my Arduino Mega2560, and an TCP-Client on windows in visualbasic.net 2015.
When i send a short code to the server it is received fine.
A short response code from the server to the client works fine also, however, when the response is bigger I receive only parts of it (very incomplete). It looks like a buffer overflow or so.

Thank in advanced.
JJ

What I have tried:

I have tried to find a solution on the internet, but till now I wasn't successful.
This is my vb.net code:

Private Function TCPConnect(TCPMessage As [String]) As String
If (TCPMessage.Length > 0) Then
Dim ServerIP As String = "192.168.0.10)
Dim ServerPort As Int32 = 10000
Dim Client As New TcpClient(ServerIP, ServerPort) 'Create a TcpClient.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(TCPMessage) ' Translate the passed message into ASCII and store it as a Byte array.
Dim stream As NetworkStream = Client.GetStream() ' Get a client stream for reading and writing. (Stream stream = client.GetStream())
stream.Write(data, 0, data.Length) ' Send the message to the connected TcpServer.
data = New [Byte](256) {} ' Receive the TcpServer.response. Buffer to store the response bytes.
Dim responseData As [String] = [String].Empty ' String to store the response ASCII representation.
Dim bytes As Int32 = stream.Read(data, 0, data.Length) ' Read the first batch of the TcpServer response bytes.
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
TCPConnect = responseData ' Return variable with response from TCP-server.
stream.Close() ' Close stream.
Client.Close() ' Close client.
Else
'TCPConnect = "Error: Empty String" ' Return variable wit response from TCP-server.
TCPConnect = "Empty String"
End If
End Function
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900