c \ # 의 SocketIoClient DotNet 라 이브 러 리 는 nodejs 의 socket. io 와 연결 할 수 있 습 니 다.

1933 단어 c#socket
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Quobject.SocketIoClientDotNet.Client;

namespace socket
{
    class Program
    {
        static void Main(string[] args)
        {

            var socket = IO.Socket("http://114.55.104.1:8090/");//     
            socket.On(Socket.EVENT_CONNECT, () =>       //    
            {
                Console.WriteLine("    ");
                socket.Emit("hi","ccdcd");     //    ,              :           ,          ,         
                socket.On("cd", (data) =>      //    
                {
		    var b=(JObject)data;  //      
		   Console.WriteLine(b['name']);
                    Console.WriteLine(data);
                    socket.Disconnect();      //    

                });
            });
            socket.Connect();   //  
            
		socket.On(Socket.EVENT_DISCONNECT,()=> {
                this.m_robot.OutLogMsg("    ");
                conn_net = false;
                socket.Close();
            });                   //socket.close();        disconnect         reconnet           
		
            Console.ReadKey();

        }
    }
}

socket 에서 제 이 슨 으로 데 이 터 를 전달 합 니 다.
                JObject a=new JObject();
                a.Add("name","liushuai");
                JArray arr = new JArray();
                arr.Add(new JValue(1));
                arr.Add(new JValue(2));
                a.Add('time',arr);
                socket.Emit("data",a);

 
참고 주소:https://stackoverflow.com/questions/39135966/unable-to-use-socketioclientdotnet-with-external-server
                  https://stackoverflow.com/questions/32190867/socket-io-in-c-socketioclientdotnet-and-socketio4net-failed

좋은 웹페이지 즐겨찾기