Shop OBEX P1 Docs P2 Docs Learn Events
Help using the Spinneret as a Client — Parallax Forums

Help using the Spinneret as a Client

Mike GMike G Posts: 2,702
edited 2010-12-12 07:31 in Accessories
I loaded Tim's "W5100 TCP Client Echo Demo indirect Ver. 00.1" and was able to hit the "TCP Test Tool 2.3" from Simple Com Tools as described in the Demo comments.

Next, I created a simple ASP.NET application on the localhost. The default.aspx page returns a datetime comma delimited string. I configured the Spinneret server to hit the localhost's IP (192.168.1.100) on port 80. When a connection is made, the Spinneret fires off the header.

GET /SpinneretUtilities/default.aspx HTTP/1.1
Host: 192.168.1.100
Keep-Alive: 115
Connection: keep-alive

I get a response from the web server and the world is great.

So I tried the same thing, this time connecting to the exact same code but on the Internet. No dice... the Spinneret waits for a connection, the header is never sent. So how do I go about troubleshooting this behavior? I'm not sure if the request is making it outside my network. The request could be making it outside but not back?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-12-03 16:30
    Have you set your router to allow outside requests to your inner network? You need to put the spinneret in the "DMZ" or allow port forwarding. This should be a function of the router.
  • Mike GMike G Posts: 2,702
    edited 2010-12-03 17:21
    Hmmm.... I have to setup port forwarding or put the Spinneret in the DMZ to allow http requests that originate from the Spinneret?
  • Mike GMike G Posts: 2,702
    edited 2010-12-05 20:21
    Yep, port forwarding was the ticket. On the router, I set the external and internal ports to 5000 and set the "To" IP address to the Spinneret's IP. The Spinneret's socket is set to 5000 too. Everything works fine now.
  • Mike GMike G Posts: 2,702
    edited 2010-12-06 06:16
    For anyone else having this problem. It turns out that port forwarding has nothing to do with the issue I was having. My ISP blocks port 80 so I'll I had to do was assign a port number, 5001, to the spinneret.
  • thingspeakthingspeak Posts: 5
    edited 2010-12-10 22:40
    @Mike

    Can you post your SPIN for this example? Or maybe some reference on how to send a GET? I am trying to get the Spinneret to send strings to ThingSpeak (thingspeak.com or 184.106.153.149).

    I am getting close with the TCP Client Demo, but I don't see how to write the HTTP GET or POST like you have referenced:

    GET /SpinneretUtilities/default.aspx HTTP/1.1
    Host: 192.168.1.100
    Keep-Alive: 115
    Connection: keep-alive

    Some spin code would be beneficial for my project. I will post my full spin once I get it operational. Thanks for your help.
  • Mike GMike G Posts: 2,702
    edited 2010-12-11 07:04
    @thingspeak, Here's a snippet. Simply, send the header strings right after making a connection. Make sure your local port is something other than 80 like 5000 and the destination port is correct. Did you know that thingsspeak is using SSL? That would be port 443...

    The connection will work but the handshake and encryption/decryption might be a little tough to code.
      repeat
    
        'Testing Socket 0's status register and looking for a server to connect to
        PST.Str(string("Waiting for a server....", PST#NL))
        repeat while !W5100.SocketTCPestablished(0)
         
        PST.Str(string("connection established, sending header", PST#NL))
    
        StringSend(0, string("GET / HTTP/1.1"))
        StringSend(0, string(Request#CR, Request#LF))
        StringSend(0, string("Host: www.thingspeak.com"))
        StringSend(0, string(Request#CR, Request#LF))
        StringSend(0, string("Keep-Alive: 115"))
        StringSend(0, string(Request#CR, Request#LF))
        StringSend(0, string("Connection: keep-alive"))
        StringSend(0, string(Request#CR, Request#LF))
        StringSend(0, string(Request#CR, Request#LF))
    
  • thingspeakthingspeak Posts: 5
    edited 2010-12-11 10:24
    Excellent, thanks Mike G.

    The website for ThingSpeak is using SSL and the API is SSL optional. For example, sending updates from the Spinnernet uses http://api.thingspeak.com/updates and getting feeds uses, http://api.thingspeak.com/channels/<c_id>/feed.json

    I will post the SPIN when I finish the testing.
  • thingspeakthingspeak Posts: 5
    edited 2010-12-11 18:24
    When I load the TCP Client Demo and just change the network settings, I am having trouble connecting to the TCP Test Tool.

    The PST always says "Waiting for a server...." - I am pointing the test tool on the same network, no firewalls. I can make the Spinnernet act as a server and that works great, but not as a client. Of the two, I thought client would be easier. Anyone have the smoking gun on why? I have noticed others having the issue? Thanks.
  • Mike GMike G Posts: 2,702
    edited 2010-12-11 19:52
    It's configuration... You want the TCP tool to listen on a port. So enter the port and click bind. Do not click the connect button! That's for using the tool as a client and a server.

    So simply enter a port like 5000 and click the "bind" button (on the right). Make sure that you configure the spinneret's destination and local port to 5000 too...
  • thingspeakthingspeak Posts: 5
    edited 2010-12-11 22:28
    I think I see now. I have went through many iterations and I can get it to work if I make the Local Socket and Destination Socket the same port number. Before I was using port 5000 (on the spinneret) and 12345 (on the TCP server tool) - for some reason I did not realize these were correlated. For example, my PC uses a different local port to retrieve a website (port 80). I will have to look into the driver, because this is not normal TCP/Socket behavior.

    Thanks for the help.
  • Mike GMike G Posts: 2,702
    edited 2010-12-12 07:31
    Port 80 is the standard HTTP port but you can use whatever port you want. The TCP tool is running on a PC that has an assigned IP address (amusing it's on a network). The PC could have (and probably does) a web server listening on port 80. So you must pick a different port in the TCP tool else you will have a conflict.

    The Spinneret can be assigned any port. I had you use 5000 because 1) that's how the demo code works. 2) if you want to connect to the Internet, you'll need to use a local port other than 80 because your ISP probably blocks port 80.

    This has noting to do with TCP stack behavior. TCP defines how packets are transported not what port to use. Ports allow many applications on a computer to share network resources concurrently.
Sign In or Register to comment.