I'm trying to transmit data through the stream
in Visual Basic .NET
I try the next:
Client:
tcpclnt = New TcpClient()
tcpclnt.Connect("127.0.0.115", 40000)
clientstream = tcpclnt.GetStream()
Dim I As Integer
Dim msg() As Byte
For I = 1 To 1000
msg = BitConverter.GetBytes(I) ' HERE IS THE PROBLEM
clientstream.Write(msg, 0, msg.Length)
Next
Server:
Public Shared bytes(1024) As Byte
Public Shared data As String = Nothing
Server = New TcpListener(IPAddress.Any, 40000)
Server.Start()
' ... some server routine
Dim serverstream As NetworkStream = myClient.GetStream()
Dim i As Int32
i = serverstream.Read(bytes, 0, bytes.Length)
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
Invoke(Sub() TextBox3.Text = "Received: " + data)
The problem is: to get data from stream it have to be Byte() type. So to put data to stream it also have to be in Byte(). But I want to transmit integers (1000 for example). It converts in 4 bytes and when server reads it he takes four different symbols, not the number 1000!
Instead of 1000
I got two spaces.