static ClientReceivers() { NetworkReceivers.RegisterClientReceiver("print", (sender, packet) => { Console.WriteLine(packet.ReadString()); }); NetworkReceivers.RegisterClientReceiver("serverJoinInfo", (sender, packet) => { Console.WriteLine("Connected to " + packet.ReadString()); }); }
private void ReceiveCallback(IAsyncResult result) { networkStream.EndRead(result); if (!IsConnected()) { Disconnect(); } try { NetworkReceivers.ServerReceive(this, new NetworkPacket(dataBuffer)); networkStream.BeginRead(dataBuffer, 0, dataBuffferSize, ReceiveCallback, null); } catch { } }