I'm using the Spinneret more like a client, I guess. It only needs to send and receive data from another website. None of the webpage is being served up from the spinneret. How could I have the Spinneret sending a request to my website on one socket, and then receiving a response from the same website on another? I wish I had some code to give you to look at...but I don't understand the W5100 Driver enough to write any code.
I also need to parse the data coming into the spinneret to get the specific data I want. How would I go about doing that. I think it would help me more if I had a ground up explanation...instead of trying to do it through your written code...because that doesn't seem to work very well for me.
How could I have the Spinneret sending a request to my website on one socket, and then receiving a response from the same website on another
That's not how HTTP works. Open a socket -> send a request -> receive a response => close the socket. I think you want two ports; one socket on port 5000 and another on 5001.
I also need to parse the data coming into the spinneret to get the specific data I want. How would I go about doing that.
The string methods object has a MatchPattern method. You could use that... it's the work horse of the entire Multi-Socket server. Moreover, I think you need to study the HTTP protocol, the Propeller manual, and the W5100 manual. Everything you're asking is available in the examples provided.
When I get home from work I'll try to whip something up as an example.
1) Add a port2 and set the tcpMask member in the DAT section
DAT
port2 word 5010
...
tcpMask byte %0111
udpMask byte %0000
2) Initialize the sockets to use IDs 0 to 2
' Initailize TCP sockets (defalut setting; TCP, Port, remote ip and remote port)
repeat id from 0 to 2
InitializeSocket(id)
Request.Release(id)
pause(50)
' Set all TCP sockets to listen
pst.char(13)
repeat id from 0 to 2
Socket.Listen(id)
pst.str(string("TCP Socket Listener ID : "))
pst.dec(id)
pst.char(13)
pause(50)
3) Execute your server request.
PUB Main | packetSize, id, i, reset, j, temp
''HTTP Service
GetMyIp(3)
The method that makes the call
PUB GetMyIp(id) | st, size, idx, tempMask
InitializeSocket2(id)
pause(delay)
'Get My IP
pst.str(string(13, "Getting Assigned IP ",13))
Socket.Connect(id)
pause(delay)
repeat while !Socket.Connected(id)
pst.str(string(13, "Connected Sending Header ",13))
'Header
StringSend(id, string("GET /spinneret/myip.aspx HTTP/1.1", 13, 10))
StringSend(id, string("Keep-Alive: 115", 13, 10))
StringSend(id, string("Host: agaverobotics.com", 13, 10))
StringSend(id, string("Connection: keep-alive", 13, 10, 13, 10))
pst.str(string(13, "Waiting for response ",13))
'Wait for response
repeat until size := Socket.rxTCP(id, @rxdata)
'Find and print the message body
idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true)
pst.str(@rxdata+idx+4)
'Reset the socket
Socket.Disconnect(id)
return
PRI InitializeSocket2(id)
Socket.Initialize(id, TCP_PROTOCOL, port2, remotePort, @remoteIp)
return
This will hit my web site and return your IP as a string.
Socket 3 is on it's own port. Every time GetMyIp(id) is invoked the connection to the server is initialized, communication happens, and the socket is disconnected. Parsing the response or request is up to you.
Comments
Check out my budding tutorial and see if that helps.
http://spinneret.servebeer.com:5000/
I also need to parse the data coming into the spinneret to get the specific data I want. How would I go about doing that. I think it would help me more if I had a ground up explanation...instead of trying to do it through your written code...because that doesn't seem to work very well for me.
The string methods object has a MatchPattern method. You could use that... it's the work horse of the entire Multi-Socket server. Moreover, I think you need to study the HTTP protocol, the Propeller manual, and the W5100 manual. Everything you're asking is available in the examples provided.
When I get home from work I'll try to whip something up as an example.
1) Add a port2 and set the tcpMask member in the DAT section
2) Initialize the sockets to use IDs 0 to 2
3) Execute your server request.
The method that makes the call
This will hit my web site and return your IP as a string.
Socket 3 is on it's own port. Every time GetMyIp(id) is invoked the connection to the server is initialized, communication happens, and the socket is disconnected. Parsing the response or request is up to you.