当前位置: 首页>>代码示例>>C#>>正文


C# IConnection.Send方法代码示例

本文整理汇总了C#中IConnection.Send方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Send方法的具体用法?C# IConnection.Send怎么用?C# IConnection.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnection的用法示例。


在下文中一共展示了IConnection.Send方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StratumMiner

        /// <summary>
        /// Creates a new miner instance.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="extraNonce"></param>
        /// <param name="connection"></param>
        /// <param name="pool"></param>
        /// <param name="minerManager"></param>
        /// <param name="storageLayer"></param>
        public StratumMiner(int id, UInt32 extraNonce, IConnection connection, IPool pool, IMinerManager minerManager, IStorageLayer storageLayer)
        {
            Id = id; // the id of the miner.
            ExtraNonce = extraNonce;
            Connection = connection; // the underlying connection.
            Pool = pool;
            _minerManager = minerManager;
            _storageLayer = storageLayer;

            Subscribed = false; // miner has to subscribe.
            Authenticated = false; // miner has to authenticate.

            _logger = Log.ForContext<StratumMiner>().ForContext("Component", pool.Config.Coin.Name);
            _packetLogger = LogManager.PacketLogger.ForContext<StratumMiner>().ForContext("Component", pool.Config.Coin.Name);

            _rpcResultHandler = callback =>
            {
                var asyncData = ((JsonRpcStateAsync)callback); // get the async data.
                var result = asyncData.Result + "\n"; // read the result.
                var response = Encoding.UTF8.GetBytes(result); // set the response.

                Connection.Send(response); // send the response.

                _packetLogger.Verbose("tx: {0}", result.PrettifyJson());
            };
        }
开发者ID:carloslozano,项目名称:CoiniumServ,代码行数:35,代码来源:StratumMiner.cs

示例2: RunClientSubscriber

        private void RunClientSubscriber(IConnection<SimpleMessage<int>, int> connection, IConnectionStubListener<SimpleMessage<int>, int> listener, ushort port)
        {
            listener.BindTo(new IPEndPoint(IPAddress.Any, port));
            var listenerTask = Task.Run(() => RunListenerSubscriber(listener));
            var ready = false;
            connection.Subscribe(0, (message, size) => ready = true);
            connection.Subscribe(1, (message, size) => TextMessageHandler("Client", message, size));
            connection.Connect(new IPEndPoint(IPAddress.Loopback, port));
            while (!ready)
                Thread.CurrentThread.Join(10);

            const int messages = 500;
            Console.WriteLine(@"Sending {0} messages with random data", 5);
            var rnd = new Random();
            for (var i = 0; i < messages; ++i)
            {
                var data = new byte[rnd.Next(16, 256)];
                rnd.NextBytes(data);
                connection.Send(new SimpleMessage<int>(1, Encoding.ASCII.GetBytes(Convert.ToBase64String(data))));
            }
            Console.WriteLine(@"Client: Done, sending exit message");
            connection.Send(new SimpleMessage<int>(2));
            connection.Disconnect();
            Console.WriteLine(@"Waiting for listener thread to exit");
            listenerTask.Wait();
            Console.WriteLine(@"Listener thread has exited");
            Console.WriteLine();
            Console.WriteLine(@"Press any key to exit");
            Console.ReadKey();
        }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:30,代码来源:TcpConnectionTests.cs

示例3: SendResponse

        private static void SendResponse(IConnection client, int requestId, IMessage message)
        {
            var packet = new BNetPacket(
                new BNetHeader(0xfe, 0x0, requestId, (uint)message.SerializedSize, 0),
                message.ToByteArray());

            client.Send(packet);
        }
开发者ID:devinvisible,项目名称:d3sharp,代码行数:8,代码来源:BNetRouter.cs

示例4: Receive

        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 });
            }
        }
开发者ID:KeithLee208,项目名称:helios,代码行数:18,代码来源:Program.cs

示例5: Check

 public void Check(IConnection connection)
 {
     log.Info("Check");
     connection.Send(new RpcMail{
         To = new ActorId("System.Nodes"),
         From = Id,
         Message = new FunctionCall("GetNodes", connection.Remote),
         MessageId = MessageId.New(),
     });
 }
开发者ID:stangelandcl,项目名称:Actors,代码行数:10,代码来源:NodeMapActor.cs

示例6: ProcessNextRequestFrom

 // ----- Public methods
 public void ProcessNextRequestFrom(IConnection connection)
 {
     try {
         var request = connection.Read();
         var response = _clientRequestProcessor.Process(request);
         connection.Send(response);
     }
     catch (NoDataToReadFromConnectionException ex) {
         throw new NoRequestToProcessException("No request is available to process.", ex);
     }
 }
开发者ID:pierregillon,项目名称:ConnectUs,代码行数:12,代码来源:ClientRequestHandler.cs

示例7: ReceiveData

        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});
        }
开发者ID:KeithLee208,项目名称:helios,代码行数:17,代码来源:Program.cs

示例8: SendRPCResponse

 private static void SendRPCResponse(IConnection connection, uint token, IMessage message, uint status)
 {
     var packet = new PacketOut(ServiceReply, 0x0, token, message, status);
     connection.Send(packet);
 }
开发者ID:midnight554,项目名称:mooege,代码行数:5,代码来源:MooNetRouter.cs

示例9: Main

        static void Main(string[] args)
        {
            RemoteHost = NodeBuilder.BuildNode().Host("192.168.0.12").WithPort(9092).WithTransportType(TransportType.Tcp);

            kafkaClient =
                new ClientBootstrap()
                    .SetTransport(TransportType.Tcp)
                    .SetDecoder(new NoOpDecoder())
                    .SetEncoder(new NoOpEncoder())
                    .RemoteAddress(RemoteHost)
                    .OnConnect(ConnectionEstablishedCallback)
                    .OnDisconnect(ConnectionTerminatedCallback)
                    .Build().NewConnection(Node.Empty().WithTransportType(TransportType.Tcp), RemoteHost);

            kafkaClient.Open();

            //            TcpClient client = new TcpClient("192.168.0.12", 9092);

            Console.Title = string.Format("KafkaClient {0}", Process.GetCurrentProcess().Id);

            kafkaClient.OnError += KafkaClient_OnError;

            var request = new MetadataRequest(new List<string> { "test_topic" });
            var requestHeader = new RequestHeader((short)ApiKeys.Metadata, "Mr Flibble", 1234);

            var buffer = new MemoryStream();

            requestHeader.WriteTo(buffer);
            request.WriteTo(buffer);

            var bytes = buffer.ToArray();

            var lenght = KafkaTypesHelper.Int32;

            buffer = new MemoryStream();

            lenght.Write(buffer, bytes.Length);

            var writter = new BinaryWriter(buffer);

            writter.Write(bytes);

            Console.WriteLine("Bytes Lenght " + bytes.Length);

            bytes = buffer.ToArray();

            HexPrint(bytes);

            //kafkaClient.Receive += KafkaClient_Receive;
            //NetworkStream nwStream = client.GetStream();
            //nwStream.Write(bytes, 0, bytes.Length);
            kafkaClient.Send(new NetworkData() { Buffer = bytes, Length = bytes.Length });

            Thread.Sleep(5000);

            kafkaClient.Send(new NetworkData() { Buffer = bytes, Length = bytes.Length });

            /*byte[] bytesToRead = new byte[client.ReceiveBufferSize];

            int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);

            bytesToRead = bytesToRead.Take(bytesRead).ToArray();

            HexPrint(bytesToRead);

            bytesToRead = bytesToRead.Skip(8).ToArray();

            var s = ProtoUtils.parseResponse((short)ApiKeys.Metadata, new MemoryStream(bytesToRead));

            var response = new MetadataResponse(s);*/

            Console.WriteLine("Press any key to exit.");

            Console.ReadLine();
        }
开发者ID:rudygt,项目名称:dot-kafka,代码行数:75,代码来源:Program.cs

示例10: DemoStrings

        private static void DemoStrings(IConnection conn)
        {
            var packet = new Packet();

            var text = new TextFile('A') {
                {"<string C/>", DisplayMode.Scroll}
            };

            packet.SetMemory(new FileTable {
                {'C', new StringFileInfo(10)},
                text
            });

            packet.Add(new WriteTextCommand(text));
            conn.Send(packet);

            for(int i = 0; i < 60; i++)
            {
                packet = new Packet();
                packet.Add(new WriteStringCommand(new StringFile('C', i.ToString("000"))));
                conn.Send(packet);
                Thread.Sleep(1000);
            }
        }
开发者ID:ungood,项目名称:OmegaNET,代码行数:24,代码来源:Program.cs

示例11: FlushOutgoingBuffer

 public static void FlushOutgoingBuffer(GameBitBuffer buffer, IConnection connection)
 {
     if (buffer.Length > 32)
     {
         var data = buffer.GetPacketAndReset();
         connection.Send(data);
     }
 }
开发者ID:darkschasu,项目名称:d3sharp,代码行数:8,代码来源:GameRouter.cs

示例12: CreateSession

        /// <summary>
        /// Creates a new session for the specified connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <returns>A new Session for the connection.</returns>
        private Session CreateSession(IConnection connection)
        {
            // Negotiate our telnet options.
            connection.TelnetCodeHandler.BeginNegotiation();

            // Load our splash screen.
            connection.Send(GetSplashScreen(), false, true);

            // Create a new session for this connection.
            var session = new Session(connection);

            // Handle our session authenticated event.
            session.SessionAuthenticated += this.OnSessionAuthenticated;

            session.SubscribeToSystem(this);

            // Add the new session to our collection.
            lock (this.Sessions)
            {
                this.Sessions.Add(connection.ID, session);
            }

            return session;
        }
开发者ID:Hobbitron,项目名称:WheelMUD,代码行数:29,代码来源:SessionManager.cs


注:本文中的IConnection.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。