Search code examples
httptcpsocket.io.net-micro-frameworkgadgeteer

.net micro framework and socket.io


I have 2 questions:

question (1): I want to connect my Gadgeteer who works on .net micro framework v4.2 via TCP to a server i wrote on node.js, but I am just stuck on

socket.Connect(new IPEndPoint(IPAddress.Parse(ip_address), port)); it's just loading. I have an ethernet module and I read at https://netmf.codeplex.com/releases/view/81000 under the title bug fixes that "Socket.Connect still blocked after reinsert ethernet cable" have this been fixed or not?

The code is:

 Connecttoserver(settings.IPAddress, 8000);

       void Connecttoserver(string ip_address, int port)
     {
          try
           {

socket = new Socket(AddressFamily.InterNetwork, 
                              SocketType.Stream, 
                                      ProtocolType.Tcp);

               socket.Connect(new IPEndPoint(IPAddress.Parse(ip_address), port));

               Send("HI !");

               ReceiveThread = new Thread(Receive);

               ReceiveThread.Start();



           }

          catch (Exception x)
           {


           }


       }

Question (2):

I want to use socket.io who is using websockets instead of TCP/IP but when I try the example from this webside https://github.com/nikkis/SocketIO.NetMF/. I can see in the output that the message has been sent but nothing happens, the server is never connected to my Gadgeteer? Can somebody help me with a socket.io server who send data to the client directly not to the browser. is that possible with socket.io in node.js?


Solution

  • To your question (2):

    Which version of Socket.IO you have for Node.js? I think the library supports version 0.9.x. Can you tell what your Node.js logs say when you try to connect your Gadgeteer? Does it receive connection event? Bellow an example to set up Node.js socket.io that should work with the library.

    var server = APP.listen( config.server.port );
    var io = socket.listen( server );
    
    io.sockets.on( 'connection', function( socket ) {
      console.log( 'connection' );
    
      socket.on( 'disconnect', function( deviceid ) {
    
        console.log( 'disconnecting ' + socket.id );
    
      } );
    
      socket.on( 'my_own_event', function( param1, param2 ) {
    
        console.log( 'executing my own event' );
    
      } );
    
    }