public ClientSession() : base() { client = new UdpClient(); state = new UdpState() { Name = "" }; msgTypes[0] = new SignalType(0, false); msgTypes[2] = new NameChangeType(2, false); msgTypes[3] = new SignalType(3, false); msgTypes[6] = new ChatType(6, false); }
private void RecvAck(IAsyncResult result) { IPEndPoint remoteIP = null; byte[] payload = null; // try // { payload = client.EndReceive(result, ref remoteIP); // } // catch (SocketException ex) // { //#if DEBUG // Console.WriteLine("UdpServer: Error {0}: {1}, retrying", ex.ErrorCode, ex.Message); //#endif // client.BeginReceive(new AsyncCallback(RecvAck), null); // return; // } byte msgType = payload[0]; object data = msgTypes[msgType].ServerFormatData(payload); UdpState state = null; if (endPoints.ContainsKey(remoteIP)) state = states[endPoints[remoteIP]]; else state = new UdpState() { EndPoint = remoteIP }; if (!OnRecv(state, msgType, data)) if (state != null && state.Initialized) RaiseMessageReceived(new NetMsgArgs(state.ID, state.Name, msgType, data)); try { client.BeginReceive(new AsyncCallback(RecvAck), null); } catch (SocketException ex) { #if DEBUG //if (ex.ErrorCode != 10054) Console.WriteLine("UdpServer: IP {0} SocketIssue. {1}", state.EndPoint, ex.Message); #endif if (!requestingHeartbeat) RequestHeartbeat(); client.BeginReceive(new AsyncCallback(RecvAck), null); } }