コード例 #1
0
        private void OnTransportReceived(IUdpTransport transport, string address, byte[] bytes)
        {
            if (bytes.Length <= _maxMessageSize)
            {
                var message = _serializer.Deserialize <IMessage>(bytes);

                switch (message.TypeMessage)
                {
                case "authorize":
                    ReceiveAuthorize(address, message);
                    break;

                case "request":
                    ReceiveRequest(address, message);
                    break;

                case "response":
                    ReceiveResponse(address, message);
                    break;

                case "error":
                    ReceiveError(address, message);
                    break;

                default:
                    Error(address, _invalidMessage);
                    break;
                }
            }
            else
            {
                Error(address, _tooBigMessage);
            }
        }
コード例 #2
0
        public ChatClient(IUdpTransport transport, ProtocolUdpNetwork network, int maxMessageLenght)
        {
            _transport = transport;
            _transport.Disconnected += TransportOnDisconnected;

            _network                  = network;
            _maxMessageLenght         = maxMessageLenght;
            _network.RequestReceived += NetworkOnRequestReceived;
            _network.Connected       += NetworkOnConnected;
            _network.Start(0);
        }
コード例 #3
0
 public TransportUdpProtocol(IUdpTransport transport, int maxMessageSize, ISerializer serializer)
 {
     _transport      = transport;
     _maxMessageSize = maxMessageSize;
     _serializer     = serializer;
 }
コード例 #4
0
 private void OnTransportDisconnected(IUdpTransport transport, string address)
 {
     CallDisconnected(address);
 }
コード例 #5
0
 private void TransportOnDisconnected(IUdpTransport transport, string address)
 {
     CallChangeStage(ClientStage.Disconnected);
     CallMessage("Disconnect", true);
 }