I have these following lines to send bytes using socket
Dim server As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim myIp As IPAddress = IPAddress.Parse("myIP")
Dim ip As New IPEndPoint(myIp, Int32.Parse("myPort"))
server.Connect(ip)
server.Send(Encoding.UTF8.GetBytes("Halo")
These are the lines I use to receive
Dim data(255) As Byte
Dim bytesReceived As Integer = socket.Receive(buffer)
Dim stringData As String = Encoding.UTF8.GetString(data)
My problem:
As in the code, I am supposed to retrieved “Halo”. Instead I keep receiving sth like “[]”. Can someone give me advise on this?
In order to receive data on a socket, you need to use the
Socket.Receivemethod. Here’s an example of what you need to do:I would recommend using a larger buffer, though, such as 4096.
http://msdn.microsoft.com/en-us/library/w89fhyex.aspx contains a few synchronous and asynchronous socket examples.