One acts as a client, the other as a server. I send two things from client to server;
1: a string describing which service of the server is needed. The server enters a sub based on this string.
2: data needed for the sub the server is in.
However, apparently the second transmission results in 8000+ zero's being recieved instead of the string i sent..
Code: Client
Expand|Select|Wrap|Line Numbers
- 'will send the info
- Public Sub sendInfo()
- 'check connection
- If Not connected Then
- Throw New Exception("There is no connection to the server.")
- End If
- 'send message
- Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("SERVICE_1")
- networkStream.Write(sendBytes, 0, sendBytes.Length)
- Dim a As String = "string to be sent for the service_1 sub of the server"
- Dim sendBytes2 As [Byte]() = Encoding.ASCII.GetBytes(a)
- networkStream.Write(sendBytes2, 0, sendBytes2.Length)
- End Sub
Code: server
Expand|Select|Wrap|Line Numbers
- 'will serve a client
- Private Sub serveClient(ByVal client As TcpClient)
- 'recieve message
- Dim bytes(client.ReceiveBufferSize) As Byte
- client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
- Dim request As String = Encoding.ASCII.GetString(bytes)
- 'check needed service
- If matches(request, "SERVICE_1") Then
- service1(client)
- ElseIf matches(request, "SERVICE_2") Then
- service2(client)
- ElseIf matches(request, "SERVICE_3") Then
- service3(client)
- End If
- End Sub
- Private Sub service1(ByVal client As TcpClient)
- Dim bytes(client.ReceiveBufferSize) As Byte
- client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
- Dim clientdata As String = Encoding.ASCII.GetString(bytes)
- Dim s() As String = clientdata.Split(";")
- If (s.Length < 3) Then
- MsgBox("string didn't contain ';' zero's recieved")
- End If
- dosomething(s(0), s(1), s(2))
- End Sub
(when I putted breakpoints on all lines, and ran through them, apparently it did recieve it correctly, but it does not do that without breakpoints)
Thanx