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


C# Socket.Recv方法代码示例

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


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

示例1: Append

        static void Append(Socket sock, string root)
        {
            var name = sock.Recv(Encoding.UTF8);
            var fileName = Path.GetFileName(name) ?? "";
            var combine = Path.Combine(root, fileName);

            var s = new FileTapeStream(combine);
            Console.WriteLine("Append {0}", fileName);
            long result = 0;
            while (true)
            {
                var verDat = sock.Recv();
                if ((null == verDat) || (verDat.Length == 0))
                    break;

                var version = BitConverter.ToInt64(verDat, 0);
                var data = sock.Recv();

                var cond = TapeAppendCondition.VersionIs(version);
                result = s.TryAppend(data, cond);
                if (result != 0)
                    Console.WriteLine("  " + result);
            }
            s.UpdateCounter(result);
            sock.Send(BitConverter.GetBytes(result));
        }
开发者ID:kstreet,项目名称:lokad-synapse,代码行数:26,代码来源:Program.cs

示例2: Recv

        public static KvMsg Recv(Socket subscriber)
        {
            var key = subscriber.Recv(Encoding.Unicode);
            var sequence = BitConverter.ToInt64(subscriber.Recv(), 0);
            var body = subscriber.Recv(Encoding.Unicode);

            return new KvMsg(sequence, key, body);
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:8,代码来源:kvsimple.cs

示例3: RecepcionHandShake

 void RecepcionHandShake(Socket socket, IOMultiPlex revents)
 {
     var idcliente = socket.Recv();
     socket.Send(nombreServidor);
     MethodInvoker action=delegate { listanodos.Items.Add(Encoding.Unicode.GetString(idcliente));};
     listanodos.BeginInvoke(action);
 }
开发者ID:majimenezp,项目名称:EjemplosZeroMQ,代码行数:7,代码来源:Form1.cs

示例4: ReceiverPollInHandler

 private static void ReceiverPollInHandler(Socket receiver, Socket sender)
 {
     var ms = receiver.Recv(Encoding.UTF8);
       var timeout = TimeSpan.FromTicks(int.Parse(ms) * 10000L);
       Console.WriteLine(ms);
       Thread.Sleep(timeout);
       sender.Send(string.Empty, Encoding.UTF8);
 }
开发者ID:nivertech,项目名称:zguide,代码行数:8,代码来源:taskwork2.cs

示例5: RecepcionDealer

 static void RecepcionDealer(Socket socket, IOMultiPlex revents)
 {
     //Repetidor(socket,router );
     var datos = socket.Recv();
     string mensaje = string.Empty;
     Guid identidad = new Guid(datos);
     if (socket.RcvMore)
     {
         //delimitador vacio
         socket.Recv();
         mensaje = socket.Recv(Encoding.Unicode);
         Console.WriteLine("Se recibio el mensaje en el dealer:" + mensaje);
     }
     router.SendMore(datos);
     router.SendMore(string.Empty, Encoding.Unicode);
     router.Send(mensaje, Encoding.Unicode);
 }
开发者ID:majimenezp,项目名称:EjemplosZeroMQ,代码行数:17,代码来源:Program.cs

示例6: FrontendPollInHandler

 private void FrontendPollInHandler(Socket socket, IOMultiPlex revents)
 {
     //  Process all parts of the message
     bool isProcessing = true;
     while (isProcessing) {
         byte[] message = socket.Recv();
         backend.Send(message, socket.RcvMore ? SendRecvOpt.SNDMORE : 0);
         isProcessing = socket.RcvMore;
     }
 }
开发者ID:nivertech,项目名称:zguide,代码行数:10,代码来源:rrbroker.cs

示例7: SendRequests

 private static void SendRequests(Socket requester)
 {
     var message = Encoding.Unicode.GetBytes("Hello");
     while (true)
     {
         requester.Send(message);
         var response = requester.Recv();
         Console.WriteLine("Response: {0}", Encoding.Unicode.GetString(response));
         Thread.Sleep(1000);
     }
 }
开发者ID:brechtvm,项目名称:presentations-zeromq,代码行数:11,代码来源:Client.cs

示例8: Worker

 private static void Worker()
 {
     using (Socket receiver = new Socket(SocketType.REP)) {
         receiver.Connect("inproc://workers");
         while (true) {
             string message = receiver.Recv(Encoding.Unicode);
             Thread.Sleep(1000);
             receiver.Send(new Message("World"));
         }
     }
 }
开发者ID:paulcbetts,项目名称:clrzmq,代码行数:11,代码来源:Program.cs

示例9: DoWork

        private void DoWork(Socket consumer, Socket reporter, string workerId)
        {
            while (true)
            {
                var message = consumer.Recv();
                ProcessWorkItem(message);

                // Signal that we've finished the workitem.
                reporter.Send(Encoding.Unicode.GetBytes(workerId));
            }
        }
开发者ID:brechtvm,项目名称:presentations-zeromq,代码行数:11,代码来源:Worker.cs

示例10: HandleRequests

        private static void HandleRequests(Socket responder)
        {
            while (true)
            {
                byte[] request = responder.Recv();
                string message = Encoding.Unicode.GetString(request);
                Console.WriteLine("Received: {0}", message);

                responder.Send(Encoding.Unicode.GetBytes("World"));
            }
        }
开发者ID:brechtvm,项目名称:presentations-zeromq,代码行数:11,代码来源:Server.cs

示例11: Transmit

 public static void Transmit()
 {
     using (var socket = new Socket(SocketType.REQ)) {
         socket.Connect("tcp://localhost:5555");
         const string request = "Hello";
         for (int requestNbr = 0; requestNbr < 10; requestNbr++) {
             Console.WriteLine("Sending request {0}...", requestNbr);
             socket.Send(new Message(request));
             var reply = socket.Recv<Message>();
             Console.WriteLine("Received reply {0}: {1}", requestNbr, reply.Msg);
         }
     }
 }
开发者ID:paulcbetts,项目名称:clrzmq,代码行数:13,代码来源:Program.cs

示例12: RecepcionRouter

 static void RecepcionRouter(Socket socket, IOMultiPlex revents)
 {
     //Repetidor(socket, dealer);
     var datos = socket.Recv();
     Guid identidad = new Guid(datos);
     if (socket.RcvMore)
     {
     //    //delimitador vacio
         socket.Recv();
         var mensaje = socket.Recv(Encoding.Unicode);
         Console.WriteLine("Se recibio el mensaje en el router:" + mensaje);
         EnviarAWorker(identidad, mensaje);
     }
 }
开发者ID:majimenezp,项目名称:EjemplosZeroMQ,代码行数:14,代码来源:Program.cs

示例13: Main

 static void Main(string[] args)
 {
     using (var ar = new AsyncDevice("inproc://server", "inproc://asyncReturn", AsyncReturn))
     using (Socket clientA = new Socket(SocketType.REQ), clientB = new Socket(SocketType.REQ)) {
         ar.Start();
         System.Threading.Thread.Sleep(1000);
         clientA.Connect("inproc://server");
         clientB.Connect("inproc://server");
         clientA.Send("Hello from A", Encoding.Unicode);
         clientB.Send("Hello from B", Encoding.Unicode);
         Console.WriteLine(clientA.Recv(Encoding.Unicode));
         Console.WriteLine(clientB.Recv(Encoding.Unicode));
         Console.ReadLine();
     }
 }
开发者ID:paulcbetts,项目名称:clrzmq,代码行数:15,代码来源:Program.cs

示例14: RelayMessage

        private static void RelayMessage(Socket source, Socket destination)
        {
            bool hasMore = true;
            while (hasMore)
            {
                // side effect warning!
                // note! that this uses Recv mode that gets a byte[], the router c# implementation
                // doesnt work if you get a string message instead of the byte[] i would prefer the solution thats commented.
                // but the router doesnt seem to be able to handle the response back to the client
                //string message = source.Recv(Encoding.Unicode);
                //hasMore = source.RcvMore;
                //destination.Send(message, Encoding.Unicode, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);

                byte[] message = source.Recv();
                hasMore = source.RcvMore;
                destination.Send(message, hasMore ? SendRecvOpt.SNDMORE : SendRecvOpt.NONE);
            }
        }
开发者ID:hnkien,项目名称:zguide2,代码行数:18,代码来源:rrbroker.cs

示例15: Main

        static void Main(string[] args)
        {
            Context contexto = new Context();
            enviar= contexto.Socket(SocketType.REQ);
            recibir = contexto.Socket(SocketType.REP);

            Console.WriteLine("Cual es el nombre del cliente");
            nombre=Console.ReadLine();
            recibir.Identity = Encoding.Unicode.GetBytes(nombre);
            enviar.Connect("tcp://127.0.0.1:5589");
            recibir.Connect("tcp://127.0.0.1:5590");
            enviar.Send(Encoding.Unicode.GetBytes(nombre));
            servidor=enviar.Recv(Encoding.Unicode);
            Console.WriteLine("Conectado");

            items[0] = recibir.CreatePollItem(IOMultiPlex.POLLIN);
            items[0].PollInHandler += new PollHandler(RecibirMensaje);
            while (true)
            {
                contexto.Poll(items, -1);
            }
            Console.ReadKey();
            enviar.Dispose();
        }
开发者ID:majimenezp,项目名称:EjemplosZeroMQ,代码行数:24,代码来源:Program.cs


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