Пример #1
0
        static void Main(string[] args)
        {
            var socket = new RequestSocket();
            socket.Options.ReceiveTimeout = null;
            socket.Options.SendTimeout = null;
            socket.Connect("tcp://localhost:6789");

            while (true)
            {
                string input;
                if ((input = ReadLine()) == "exit")
                {
                    break;
                }

                if (input == null)
                {
                    continue;
                }

                var bytesToSend = Encoding.UTF8.GetBytes(input);
                socket.Send(bytesToSend);
                var receivedBytes = socket.Receive();
                WriteLine($"Получено {Encoding.UTF8.GetString(receivedBytes)}");
            }
        }
Пример #2
0
 static void Node1(string url)
 {
     using (var s = new RequestSocket())
     {
         s.Connect(url);
         const string sendText = "Hello, World!";
         Console.WriteLine("NODE1: SENDING \"" + sendText + "\"");
         s.Send(Encoding.UTF8.GetBytes(sendText));
         Console.WriteLine("NODE1: RECEIVED: \"" + Encoding.UTF8.GetString(s.Receive()) + "\"");
     }
 }
        public ApiSchema.ApiObject SendMessage(string message)
        {
            using(var s = new RequestSocket())
            {
                s.Connect(_url);
                s.Send(Encoding.UTF8.GetBytes(message));

                //return Encoding.UTF8.GetString(s.Receive());
                return ApiSchema.Helpers.DeserializeObject(s.Receive());
            }
        }
Пример #4
0
        public static void Execute(string[] args)
        {
            const string socketAddress = "tcp://127.0.0.1:5088";

            if (args[1] == "client")
            {
                using (var req = new RequestSocket())
                {
                    req.Connect(socketAddress);
                    req.Send(Encoding.UTF8.GetBytes("hello from client"));
                    Console.WriteLine("Message from SERVER: " + Encoding.UTF8.GetString(req.Receive()));

                    Console.WriteLine("CLIENT finished");
                }
            }

            else if (args[1] == "server")
            {
                using (var rep = new ReplySocket())
                {
                    rep.Bind(socketAddress);

                    var listener = new NanomsgListener();
                    listener.AddSocket(rep);
                    listener.ReceivedMessage += socketId =>
                        {
                            Console.WriteLine("Message from CLIENT: " + Encoding.UTF8.GetString(rep.Receive()));
                            rep.Send(Encoding.UTF8.GetBytes("hello from server"));
                            Console.WriteLine("SERVER Finished");
                            Environment.Exit(0);
                        };

                    listener.Listen(null);
                }
            }
            else
            {
                Console.WriteLine("Unknown argument: " + args[1]);
            }
        }
Пример #5
0
        public void _socketfun()
        {
            _requestSocket = new RequestSocket();
            _requestSocket.Connect("tcp://" + Global.Instance.NNFConIp + ":" + Global.Instance.NNFConPUBPort);

            _subscribeSocket = new SubscribeSocket();
            _subscribeSocket.Connect("tcp://" + Global.Instance.NNFConIp + ":" + Global.Instance.NNFConSUBPort);

            long client_Autoid =Global.Instance.ClientId- 100;

               _subscribeSocket.Subscribe(BitConverter.GetBytes((short)MessageType.LOGIN).Concat(BitConverter.GetBytes(Global.Instance.ClientId)).ToArray());
            //    _subscribeSocket.Subscribe(BitConverter.GetBytes((short)MessageType.ORDER).Concat(BitConverter.GetBytes(Global.Instance.ClientId)).ToArray());

               if (Global.Instance.Relogin != true)
            {
                dllevent += new dll(checkCase);

                _CTS = new CancellationTokenSource();

            }
        }
Пример #6
0
        /// <summary>
        ///     A simple example showing use of NNanomsg.Socket
        ///     For further example usage, check out the Test project.
        /// </summary>
        static void Main(string[] args)
        {
            const string socketAddress = "tcp://127.0.0.1:5088";

            if (args[0] == "client")
            {
                using (var req = new RequestSocket())
                {
                    req.Connect(socketAddress);

                    using (var ms = new MemoryStream())
                    {
                        using (var sw = new StreamWriter(ms))
                        {
                            sw.Write("hello from client");
                        }
                        req.Send(ms.ToArray());
                    }

                    using (var ms = new MemoryStream(req.Receive()))
                    using (var sr = new StreamReader(ms))
                    {
                        Console.WriteLine("Message from SERVER: " + sr.ReadToEnd());
                    }

                    Console.WriteLine("CLIENT finished");
                }
            }

            else if (args[0] == "server")
            {
                using (var rep = new ReplySocket())
                {
                    rep.Bind(socketAddress);

                    var listener = new NanomsgListener();
                    listener.AddSocket(rep);
                    listener.ReceivedMessage += socketId =>
                        {
                            using (var ms = new MemoryStream(rep.Receive()))
                            using (var sr = new StreamReader(ms))
                            {
                                Console.WriteLine("Message from CLIENT: " + sr.ReadToEnd());
                            }

                            using (var ms = new MemoryStream())
                            {
                                using (var sw = new StreamWriter(ms))
                                {
                                    sw.Write("hello from server");
                                }
                                rep.Send(ms.ToArray());
                            }

                            Console.WriteLine("SERVER Finished");
                            Environment.Exit(0);
                        };

                    listener.Listen(null);
                }
            }
            else
            {
                Console.WriteLine("Unknown argument: " + args[0]);
            }
        }