I have 2 instances of server.
Both instances create UDP socket listening for incoming messages.
It seems that only 1 instace of my server can listen to the messages, the other seems to see that the UDP socket is not available when it suppose to receive.
Below are portion of my code:
Expand|Select|Wrap|Line Numbers
- Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); udpSocket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer,BufferCapacity);
- udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
- int servicePort = (int)transport.Properties["port"];
- System.Net.IPEndPoint localEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, servicePort);
- IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
- EndPoint tempRemoteEndPoint = (EndPoint)sender;
- udpSocket.Bind(localEndPoint);
- while (keepAlive)
- {
- fetchSignal.WaitOne();
- //This call is made to yield processor resources, Remote Client doesn't
- //consume 100% of the CPU.
- Thread.Sleep(1);
- while (keepFetching && (udpSocket.Available > 0)) //only if data is available..
- {
- .......
- }
- }
NOTE: The 2nd instance see that the udpSocket.Available is 0. While the 1st instance can see that the udpSocket is greater than 0.