Пример #1
0
    private static void Send(IProtocol protocol)
    {
        using (var bw = new BinaryWriter(networkStream, Encoding.Default, true)) {
            protocol.Write(bw);

            byte[] writeBuffer = new byte[protocol.GetPacketLength()];
            networkStream.Write(writeBuffer);
        }
    }
    public void SendPacket(IProtocol protocol)
    {
        using (var bw = new BinaryWriter(networkStream, Encoding.Default, true)) {
            protocol.Write(bw);
        }


        byte[] writeBuffer = new byte[protocol.GetPacketLength()];

        try {
            networkStream.Write(writeBuffer);
        } catch (Exception e) {
            Console.WriteLine(e);
            connectedServer.OnClientLeave(session_id);
            return;
        }
    }