I have two programs use to communicate with each other via UDP protocol (client and server), but when the client connects to the server using the method Connect (
string hostname,
int port
), Nothing happened.
This is code:
udpclient.Connect("asuspc",6500);
string duongdan = tbduongdan.Text;
Byte[] sendbyte = Encoding.ASCII.GetBytes(duongdan);
udpclient.Send(sendbyte, sendbyte.Length);
“asuspc” is name of computer that i intend to connect.
After a while to find out, I know that the hostname is “The DNS name of the remote host” rather than the name of computer, then what is “The DNS name of the remote host”?How to know “The DNS name of the remote host” of a computer?
By definition, UDP is a connection-less protocol. You do not need to connect in order to send/receive data.
Note that calling
Connect()on aUdpClientobject does nothing other than setting a default remote host so that you won’t have to specify it each time you use theSendmethod. So don’t expect anything to “happen” after the client calls theConnectmethod.With that out of the way, if both your server and your client are on your private LAN, why don’t you use the computer’s IP? e.g.