public void ReceiveWithTimeout(Byte[] receiveBuffer, Int32 timeoutMillis) { Console.WriteLine("{0} [{1}] Select timeout is {2} seconds", DateTime.Now, accessorHostString, timeoutMillis / 1000); SingleObjectList list = new SingleObjectList(accessorSocket); try { Socket.Select(list, null, null, timeoutMillis * 1000); } catch (Exception e) { Console.WriteLine("{0} [{1}] Select threw exception : {2}", DateTime.Now, accessorHostString, e.ToString()); accessorSocket = null; accessorReceiveHandler = null; return; } if (list.obj != null) { Int32 bytesRead = 0; try { bytesRead = accessorSocket.Receive(receiveBuffer); } catch (Exception) { } if (bytesRead <= 0) { accessorSocket = null; accessorReceiveHandler = null; } else { accessorReceiveHandler.HandleData(receiveBuffer, 0, (UInt32)bytesRead); } } }
public UdpConnectedClientTransmitter(EndPoint serverEndPoint) { this.udpSocket = new Socket(serverEndPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp); this.udpSocket.Connect(serverEndPoint); this.list = new SingleObjectList(); }