hi im creating a client and server application that communicates with each other. Im just wondering why i cant read the data send from the client to my server (listener)application?
HEre is my code
Client:
Server code:
HEre is my code
Client:
Code:
Dim s As Socket
Dim SendData As String = "Sending this from client application."
Try
s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
s.Connect(Sethost("127.0.0.1", 9999))
Dim msg As Byte() = Encoding.ASCII.GetBytes(SendData)
Console.WriteLine(Encoding.ASCII.GetString(msgbytes))
s.Send(msg, msg.Length, SocketFlags.None)
Catch ex As SocketException
Console.WriteLine(("Source : " + ex.Source))
Console.WriteLine(("Message : " + ex.Message))
End Try
Server code:
Code:
Dim serverlistener As TcpListener
Dim s As Socket
Dim Str() As Byte
Dim tclient As TcpClient
Try
Dim port As Int32 = 9999
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")
ServerListener = New TcpListener(localAddr, port)
ServerListener.Start()
While True
s = serverlistener.AcceptSocket
Console.WriteLine("socket connection accepted")
s.Receive(Str, s.Available, SocketFlags.None)
Console.WriteLine(Encoding.ASCII.GetString(sStr))
Console.ReadLine()
End While
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.ReadLine()
End Try