mIP how to make a socket request?

Hello,

I downloaded mIP and integrated on my project and the examples work really nice. I also managed to listen to a port and process requests but I am a bit confused how would I send a reply back. I have seen Support to send http requests but I am working at the socket level.

Any hints would be really nice.

Thanks,
Lucas

mIP does not have something like a socket.
There must be a different way to send replies.
If I remember right the closest thing to a socket was something called connection.

The web server example shows a request response exchange. You listen to the desired port and attach an event handler. When you get a request on the port, the event will fire. You can then respond in that in the handler. This is the example I am referring to:

http://mip.codeplex.com/SourceControl/latest#NetworkingExample/WebServerProgram.cs

Exactly, they provide two examples the webserver and an udp request.

My problem with the response in the webserver is that it uses the http protocol but I don’t need it. I tried to send an udp response but I got an error

I opened a TCP connection and when I receive something I tried to send an UDP request
and got an RX Error Detected

 
        void Adapter_OnTcpReceivedPacketEvent(Packet packet)
        {
            byte[] content = packet.Content;
            rs232.serialPort.Write(content);
            byte[] destIP = new byte[]{ 0xc0, 0xa8, 0x00, 0x01 };
            Networking.UDP.SendUDPMessage(content, destIP, 1000, 1000);
        }

I already have a connection open, I am trying to find out how I can reuse this connection to send bytes back.

Thanks I found out. It was simpler than expected.


   void Adapter_OnTcpReceivedPacketEvent(Packet packet)
        {
            byte[] content = packet.Content;
            String contentText = ByteToHexBitFiddle(content);
            
            Microsoft.SPOT.Trace.Print("GOT SOMETHING:"+contentText);
            rs232.serialPort.Write(content);
            packet.Socket.SendAsync(packet.Content);
         }

I didn’t expect the socket to be inside the packet.

Thanks

Awesome. When I wrote mIP, I was convinced that I could write an API that was WAY simpler than the existing ones. I was determined to make the common tasks work with a handful of lines of code. So I didn’t even look at the existing stuff. It was kinda test-driven. I wrote the simplest web server I could think of and made the API do it. That’s why it looks nothing like the standard networking classes.

I just had the displeasure of using the WinRT classes for sockets and boy is that an ugly and painful experience. You have to do all this crazy stream binding and flushing and async calls and if something goes wrong the exceptions are useless with some COM references and useless exception codes. Now, I made it all work, but at this point, the APIs should be getting easier, not harder.

Ugh. I got off track there. Anyway, thanks for the compliment :slight_smile:

2 Likes