コード例 #1
0
ファイル: HeliosTcpTransport.cs プロジェクト: pdoh00/akka.net
 protected override void OnMessage(NetworkData data, IConnection responseChannel)
 {
     if (data.Length > 0)
     {
         ChannelLocalActor.Notify(responseChannel, new InboundPayload(FromData(data)));
     }
 }
コード例 #2
0
 protected override void ReceivedData(NetworkData availableData, ReactorResponseChannel responseChannel)
 {
     if (EventLoop.Receive != null)
     {
         EventLoop.Receive(availableData, responseChannel);
     }
 }
コード例 #3
0
            private void TempServer_OnReceive(Helios.Net.NetworkData incomingData, IConnection connection)
            {
                ThreadHelper.TryLock(this.lockobj,
                                     () => {
                    Request msg       = default(Request);
                    Response response = default(Response);
                    msg = SP.Deserialize <Request>(incomingData.Buffer);

                    Func <Request, Response> clientRequestAction = null;
                    bool hasRequestAction = this._lisenter.ReceiveEvents.TryGetValue(msg.MessageType, out clientRequestAction);
                    if (hasRequestAction)
                    {
                        response = clientRequestAction.Invoke(msg);
                    }
                    var sendBuffer = SP.Serialize(response);        // serialize response message and send it to client
                    connection.Send(new Helios.Net.NetworkData
                    {
                        Buffer     = sendBuffer,
                        Length     = sendBuffer.Length,
                        RemoteHost = connection.RemoteHost
                    });
                }, (error) => {
                    throw error;
                });
            }
コード例 #4
0
ファイル: Program.cs プロジェクト: KeithLee208/helios
 private static void ReceivedCallback(NetworkData data, IConnection responseChannel)
 {
     var timeStr = Encoding.UTF8.GetString(data.Buffer);
     if (ThreadLocalRandom.Current.Next(0, 1000) == 1)
     {
         Console.WriteLine("Received: {0}", timeStr);
     }
 }
コード例 #5
0
ファイル: SocketClient.cs プロジェクト: KeithLee208/helios
 private void ReceivedDataCallback(NetworkData incomingData, IConnection responseChannel)
 {
     Invoke((Action)(() =>
     {
         AppendStatusText(string.Format("Received {0} bytes from {1}", incomingData.Length,
             incomingData.RemoteHost));
         AppendStatusText(Encoding.UTF8.GetString(incomingData.Buffer));
     }));
 }
コード例 #6
0
 /// <summary>
 /// Converts a <see cref="ByteString"/> structure into a Helios <see cref="NetworkData"/> structure
 /// </summary>
 /// <param name="byteString">The data to send over the network</param>
 /// <param name="address">The address that we received data from / are sending data to</param>
 /// <returns>a new <see cref="NetworkData"/> struct</returns>
 public static NetworkData ToData(ByteString byteString, Address address)
 {
     var data = new NetworkData()
     {
         Buffer = byteString.ToByteArray(),
         RemoteHost = HeliosTransport.AddressToNode(address)
     };
     data.Length = data.Buffer.Length;
     return data;
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: KeithLee208/helios
        public static void ReceiveData(NetworkData data, IConnection connection)
        {
            var node = connection.RemoteHost;

            ServerPrint(connection.RemoteHost, string.Format("recieved {0} bytes", data.Length));
            var str = Encoding.UTF8.GetString(data.Buffer).Trim();
            if (str.Trim().Equals("close"))
            {
                connection.Close();
                return;
            }
            ServerPrint(connection.RemoteHost, string.Format("recieved \"{0}\"", str));
            ServerPrint(connection.RemoteHost,
                string.Format("sending \"{0}\" back to {1}:{2}", str, node.Host, node.Port));
            var sendBytes = Encoding.UTF8.GetBytes(str + Environment.NewLine);
            connection.Send(new NetworkData() {Buffer = sendBytes, Length = sendBytes.Length, RemoteHost = node});
        }
コード例 #8
0
        public void Encode(NetworkData data, out List<NetworkData> encoded)
        {
            var length = data.Length + _lengthAdjustment;
            if (_lengthIncludesLenghtFieldLength)
            {
                length += _lengthFieldLength;
            }

            encoded = new List<NetworkData>();
            if (length < 0)
                throw new ArgumentException(string.Format("Adjusted frame length ({0}) is less than zero", length));

            var newData = new byte[0];
            using (var memoryStream = new MemoryStream())
            {
                switch (_lengthFieldLength)
                {
                    case 1:
                        if (length >= 256)
                            throw new ArgumentException("length of object does not fit into one byte: " + length);
                        memoryStream.Write(BitConverter.GetBytes((byte) length), 0, 1);
                        break;
                    case 2:
                        if (length >= 65536)
                            throw new ArgumentException("length of object does not fit into a short integer: " + length);
                        memoryStream.Write(BitConverter.GetBytes((ushort) length), 0, 2);
                        break;
                    case 4:
                        memoryStream.Write(BitConverter.GetBytes((uint) length), 0, 4);
                        break;
                    case 8:
                        memoryStream.Write(BitConverter.GetBytes((long) length), 0, 8);
                        break;
                    default:
                        throw new Exception("Unknown lenght field length");
                }

                memoryStream.Write(data.Buffer, 0, data.Length);
                newData = memoryStream.GetBuffer();
            }

            var networkData = NetworkData.Create(data.RemoteHost, newData,
                _lengthIncludesLenghtFieldLength ? length : length + _lengthFieldLength);
            encoded.Add(networkData);
            HeliosTrace.Instance.EncodeSuccess();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: KeithLee208/helios
        public static void Receive(NetworkData data, IConnection channel)
        {
            var command = Encoding.UTF8.GetString(data.Buffer);

            //Console.WriteLine("Received: {0}", command);
            if (command.ToLowerInvariant() == "gettime")
            {
                var time = Encoding.UTF8.GetBytes(DateTime.Now.ToLongTimeString());
                channel.Send(new NetworkData() { Buffer = time, Length = time.Length, RemoteHost = channel.RemoteHost });
                //Console.WriteLine("Sent time to {0}", channel.Node);
            }
            else
            {
                Console.WriteLine("Invalid command: {0}", command);
                var invalid = Encoding.UTF8.GetBytes("Unrecognized command");
                channel.Send(new NetworkData() { Buffer = invalid, Length = invalid.Length, RemoteHost = channel.RemoteHost });
            }
        }
コード例 #10
0
 public void Send(NetworkData payload)
 {
     UnderlyingConnection.Send(payload);
 }
コード例 #11
0
 public virtual void Send(NetworkData data)
 {
     _reactor.Send(data);
 }
コード例 #12
0
 public static Stream ToStream(this NetworkData nd)
 {
     return(new MemoryStream(nd.Buffer, 0, nd.Length));
 }
コード例 #13
0
ファイル: ReactorBase.cs プロジェクト: KeithLee208/helios
 public Task SendAsync(NetworkData payload)
 {
     return TaskRunner.Run(() => Send(payload));
 }
コード例 #14
0
        protected void Init(IConnection channel, INode remoteSocketAddress, Address remoteAddress, NetworkData msg,
            out AssociationHandle op)
        {
            var localAddress = HeliosTransport.NodeToAddress(channel.Local, WrappedTransport.SchemeIdentifier,
                WrappedTransport.System.Name, WrappedTransport.Settings.Hostname);

            if (localAddress != null)
            {
                var handle = CreateHandle(channel, localAddress, remoteAddress);
                handle.ReadHandlerSource.Task.ContinueWith(s =>
                {
                    var listener = s.Result;
                    RegisterListener(channel, listener, msg, remoteSocketAddress);
                }, TaskContinuationOptions.AttachedToParent & TaskContinuationOptions.ExecuteSynchronously & TaskContinuationOptions.NotOnCanceled & TaskContinuationOptions.NotOnFaulted);
                op = handle;
            }
            else
            {
                op = null;
                channel.Close();
            }
        }
コード例 #15
0
 protected void InvokeReceiveIfNotNull(NetworkData data)
 {
     if (Receive != null)
     {
         Receive(data, this);
     }
 }
コード例 #16
0
 protected override void OnMessage(NetworkData data, IConnection responseChannel)
 {
     var protoMessage = _protobufDecoder.Decode(data.Buffer);
     var testkitMesage = _msgDecoder.Decode(protoMessage);
     _handler.OnMessage(testkitMesage, responseChannel);
 }
コード例 #17
0
 public override void Send(NetworkData data)
 {
     HeliosTrace.Instance.TcpInboundSendQueued();
     SendInternal(data.Buffer, 0, data.Length, data.RemoteHost);
 }
コード例 #18
0
 protected abstract void RegisterListener(IConnection channel, IHandleEventListener listener, NetworkData msg,
     INode remoteAddress);
コード例 #19
0
ファイル: DummyConnection.cs プロジェクト: KeithLee208/helios
 public void Send(NetworkData data)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 protected abstract void OnMessage(NetworkData data, IConnection responseChannel);
コード例 #21
0
ファイル: Program.cs プロジェクト: rudygt/dot-kafka
 private static void ReceivedDataCallback(NetworkData incomingData, IConnection responseChannel)
 {
     Console.WriteLine("Incomming Data ");
     HexPrint(incomingData.Buffer);
 }
コード例 #22
0
 /// <summary>
 /// Converts a <see cref="NetworkData"/> structure into a <see cref="ByteString"/>
 /// </summary>
 /// <param name="data">The data we received from the network</param>
 /// <returns>A populated <see cref="ByteString"/> instance</returns>
 public static ByteString FromData(NetworkData data)
 {
     return ByteString.CopyFrom(data.Buffer, 0, data.Length);
 }
コード例 #23
0
ファイル: Program.cs プロジェクト: rudygt/dot-kafka
 private static void KafkaClient_Receive(NetworkData incomingData, IConnection responseChannel)
 {
     Console.WriteLine("Data Received ... ");
     HexPrint(incomingData.Buffer);
 }
コード例 #24
0
ファイル: ReactorBase.cs プロジェクト: KeithLee208/helios
 public void Send(NetworkData data)
 {
     Send(data.Buffer, 0, data.Length, data.RemoteHost);
 }
コード例 #25
0
        protected void InitInbound(IConnection connection, INode remoteSocketAddress, NetworkData msg)
        {
            _associationListenerTask.ContinueWith(r =>
            {
                var listener = r.Result;
                var remoteAddress = HeliosTransport.NodeToAddress(remoteSocketAddress, WrappedTransport.SchemeIdentifier,
                    WrappedTransport.System.Name);

                if (remoteAddress == null) throw new HeliosNodeException("Unknown inbound remote address type {0}", remoteSocketAddress);
                AssociationHandle handle;
                Init(connection, remoteSocketAddress, remoteAddress, msg, out handle);
                listener.Notify(new InboundAssociation(handle));

            }, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted);
        }
コード例 #26
0
 protected void InitOutbound(IConnection channel, INode remoteSocketAddress, NetworkData msg)
 {
     AssociationHandle handle;
     Init(channel, remoteSocketAddress, RemoteAddress, msg, out handle);
     StatusPromise.SetResult(handle);
 }
コード例 #27
0
 protected override void RegisterListener(IConnection channel, IHandleEventListener listener, NetworkData msg, INode remoteAddress)
 {
     ChannelLocalActor.Set(channel, listener);
     BindEvents(channel);
 }
コード例 #28
0
        /// <summary>
        /// Method is called directly by the <see cref="ReactorBase"/> implementation to send data to this <see cref="IConnection"/>.
        /// 
        /// Can also be called by the socket itself if this reactor doesn't use <see cref="ReactorProxyResponseChannel"/>.
        /// </summary>
        /// <param name="data">The data to pass directly to the recipient</param>

        internal virtual void OnReceive(NetworkData data)
        {
            if (NetworkEventLoop.Receive != null)
            {
                NetworkEventLoop.Receive(data, this);
            }
            else
            {
                UnreadMessages.Enqueue(data);
            }
        }
コード例 #29
0
ファイル: ProxyReactorBase.cs プロジェクト: helios-io/helios
 protected override void ReceivedData(NetworkData availableData, ReactorResponseChannel responseChannel)
 {
     responseChannel.OnReceive(availableData);
 }
コード例 #30
0
 public void InvokeReceiveIfNotNull(NetworkData data)
 {
     OnReceive(data);
 }
コード例 #31
0
ファイル: HeliosHelpers.cs プロジェクト: pdoh00/akka.net
 public Task SendAsync(NetworkData payload)
 {
     return UnderlyingConnection.SendAsync(payload);
 }