コード例 #1
0
        public void NamespaceExample()
        {
            // two ways to work with namespace - your preference - they function exactly the same
            //   note: only one handler is allowed per event name, the last handler registered wins!
            //   event names are logically == (eventName + endpoint)

            // traditional socket.io syntax style
            if (logger == null)
            {
                logger = socket.Connect("/logger");                 // connect to the logger ns on server, must use '/' dir prefix
            }
            logger.On("traceEvent", (eventLog) =>
            {
                Console.WriteLine("recv #2 [logger].[traceEvent] : {0}", eventLog.Json.GetFirstArgAs <EventLog>().ToJsonString());
            });
            // optional way - using EventMessage by namespace
            //socket.On("traceEvent", "/logger", (eventLog) =>
            //{
            //    Console.WriteLine("recv #1 [logger].[traceEvent] : {0}\r\n", eventLog.Json.GetFirstArgAs<EventLog>().ToJsonString());
            //});

            Console.WriteLine("Emit [logger].[messageAck] - should recv callback [logger].[messageAck]");
            logger.Emit("messageAck", new { hello = "papa" }, (callback) =>
            {
                var jsonMsg = callback as JsonEncodedEventMessage;                 // callback will be of type JsonEncodedEventMessage, cast for intellisense
                Console.WriteLine(string.Format("recv [logger].[messageAck]: {0} \r\n", jsonMsg.ToJsonString()));
            });
        }
コード例 #2
0
 public void Execute()
 {
     Console.WriteLine("Starting SocketIO4Net Client Events Example...");
     socket          = new Client(localSocketUrl);
     socket.Opened  += SocketOpened;
     socket.Message += SocketMessage;
     socket.SocketConnectionClosed += SocketConnectionClosed;
     socket.Error += SocketError;
     // register for 'connect' event with io server
     socket.On("connect", (fn) =>
     {                               // connect to namespace
         nsTarget = socket.Connect("/namespacename");
         nsTarget.On("connect", (cn) => nsTarget.Emit("test", new { data = "CONNECTED" }));
         nsTarget.On("first", (message) =>
         {
             Console.WriteLine("recv [socket].[update] event");
             Console.WriteLine("  raw message:      {0}", message.RawMessage);
             Console.WriteLine("  string message:   {0}", message.MessageText);
             Console.WriteLine("  json data string: {0}", message.Json.ToJsonString());
         });
     });
     // make the socket.io connection
     socket.Connect();
 }
コード例 #3
0
        public void Execute()
        {
            Console.WriteLine("Starting SocketIO4Net Client Events Example...");
            string ioServer = string.Format("https://api.icbit.se/icbit?AuthKey={0}&UserId={1}", authKey, userId);

            socket = new Client(ioServer);

            socket.Opened  += SocketOpened;
            socket.Message += SocketMessage;
            socket.SocketConnectionClosed += SocketConnectionClosed;
            socket.Error += SocketError;


            // register for 'connect' event with io server
            socket.On("connect", (fn) =>
            {                                                                           // connect to namespace
                icbit = socket.Connect("/icbit");
                icbit.On("connect", (cn) => icbit.Emit("message", new { op = "subscribe", channel = "orderbook_BUM3" }));
            });

            // make the socket.io connection
            socket.Connect();
        }