void HandleData(NetIncomingMessage message) { ushort id = ushort.MaxValue; ByteBuffer byteBuffer = null; try { id = message.ReadUInt16(); ushort len = message.ReadUInt16(); byteBuffer = ByteBufferPool.Alloc(len); message.ReadBytes(byteBuffer.Data, 0, len); var result = dispatcher.Fire(message.SenderConnection, (MessageID)id, byteBuffer, message); if (result != MessageHandleResult.Processing) { ByteBufferPool.Dealloc(ref byteBuffer); } } catch (Exception e) { ByteBufferPool.Dealloc(ref byteBuffer); NetLog.Exception("HandleData throws exception", e); if (id != ushort.MaxValue) { NetLog.Error("Caught exception when processing message " + (MessageID)id); } else { NetLog.Error("Caught exception when processing message"); } } }
public void Update() { if (null == mNetServer) { return; } NetIncomingMessage message; while (null != (message = mNetServer.ReadMessage())) { try { switch (message.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: { HandleDebugMessage(message); break; } case NetIncomingMessageType.ConnectionApproval: { HandleConnectionApproval(message); break; } case NetIncomingMessageType.StatusChanged: { HandleStatusChanged(message); break; } case NetIncomingMessageType.Data: { HandleData(message); break; } default: { NetLog.WarnFormat( "{0} Unhandled message type:{1}, bytes:{2}", appIdentifier, message.MessageType, message.LengthBytes); break; } } } catch (Exception e) { NetLog.Exception(appIdentifier, e); } mNetServer.Recycle(message); } }
public void Update() { if (null == mNetClient) { return; } NetIncomingMessage message; while (null != (message = mNetClient.ReadMessage())) { try { switch (message.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: { HandleDebugMessage(message); break; } case NetIncomingMessageType.StatusChanged: { HandleStatusChanged(message); break; } case NetIncomingMessageType.Data: { HandleData(message); break; } default: { NetLog.WarnFormat( "Unhandled message type:{0}, bytes:{1}", message.MessageType, message.LengthBytes); break; } } } catch (Exception e) { NetLog.Exception(e); } mNetClient.Recycle(message); } }
public static void OnMessageReceievedInvoke(NetPeer peer, SocketConnection c, int dataSize, byte[] data, string msgName) { #if SHOW_GLOBAL_INVOKES NetLog.Debug("Invoking callback OnMessageReceieved"); #endif foreach (SocketEventListenerBase cb in Callbacks) { try { cb.OnMessageReceieved(peer, c, dataSize, data, msgName); } catch (System.Exception exn) { NetLog.Exception(exn); } } }
void HandleData(NetIncomingMessage message) { MessageID id = (MessageID)message.ReadUInt16(); ushort len = message.ReadUInt16(); ByteBuffer byteBuffer = ByteBufferPool.Alloc(len); try { message.ReadBytes(byteBuffer.Data, 0, len); var result = dispatcher.Fire(message.SenderConnection, id, byteBuffer, message); if (result != MessageHandleResult.Processing) { ByteBufferPool.Dealloc(ref byteBuffer); } } catch (Exception e) { ByteBufferPool.Dealloc(ref byteBuffer); NetLog.Exception("HandleData throws exception", e); } }