Hi all,
I am new to network programming and I already read some examples related to socket on the MSDN and now I am trying to create a message sender(server) and a message receiver(client) by using TcpClient and TcpListener.
The server simply contains a TcpListener object that runs the following code when it is started:
listener.Start()
client = listener.AcceptTcpClient()
The client contains a TcpClient object that is used to connect to the server:
client.Connect(IPAddress.Parse(127.0.0.1), 2828)
After the client gets connected to the server, sometime later, the server attempts to send a message to the client by using the following code:
Dim message As String="Hello World"
Dim encoding As New System.Text.ASCIIEncoding()
Dim bytes As Byte()
bytes = encoding.GetBytes(s)
Dim ns As NetworkStream=client.GetStream()
ns.Write(s, 0, bytes.Length)
Then the client needs some codes to receive this message, the problem is how the client can know WHEN the server sends it a message so that it can call the codes that will receive the message
Thank you very much for your help.
.NET Development20
|