Ejemplo n.º 1
0
    public static MessageHandler Write(CancelableTcpClient client, MessageTransferLookUp lookUp)
    {
        var messageData = NetworkMessageSerializer.Get(lookUp);

        return((opCode, toSend) => {
            int length = messageData.serialize(opCode, toSend);
            client.Write(messageData.buffer, 0, length);
            return length;
        });
    }
    public static NetworkMessageStream Open(int port, string address, MonoBehaviour parent, MessageTransferLookUp lookUp)
    {
        var            addr        = IPAddress.Parse(address);
        var            client      = new CancelableTcpClient(new TcpClient(address, port));
        var            messageData = NetworkMessageSerializer.Get(lookUp);
        var            recieve     = ConnectionRead.Read(client, parent, lookUp);
        MessageHandler send        = ConnectionWrite.Write(client, lookUp);

        return(new NetworkMessageStream(send, recieve));
    }