C# UDP Client/Server
Hi, I've recently been doing some coding for a client and server in C#, It was all working perfectly before on lan, then i started to play with it running over the net. Now i can't run both on the same pc, the client doesn't compile and gives an exception "Only one usage of each socket address (protocol/network address/port) is normally permitted" i thought that was fairly self explanitory but i can't for the life of me figure out how to fix it? Any ideas? The codes still fairly standard, if its not obvious how to fix it, i can post it later, Thanks in advance, Draconis
It sounds as if your client is doing a bind to the same port number as the server.
Typically, only a server will bind to an address; a client will let the system choose the address, and not do a bind on its socket. That way, the system can choose a port that's not in use, and client and server can both run on the same system.
The client will use sendto() (specifying an address to the send command) to send to the server; the server will use recvfrom() (receiving the source address along with the data) and return data to the client using another sendto().
Typically, only a server will bind to an address; a client will let the system choose the address, and not do a bind on its socket. That way, the system can choose a port that's not in use, and client and server can both run on the same system.
The client will use sendto() (specifying an address to the send command) to send to the server; the server will use recvfrom() (receiving the source address along with the data) and return data to the client using another sendto().
enum Bool { True, False, FileNotFound };
ok that makes sense, but i've been using this code(below) to send and recieve data
It has been working but is this an older way to do it?
string sendString = (ip + "@" + msg); byte[] sendData = encode.GetBytes(sendString); try { //Send to Server client.Send(sendData, sendData.Length, ip, port); //Receive DataGram from Server byte[] recData = client.Receive(ref receivePoint);
It has been working but is this an older way to do it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement