I am attempting to understand how sockets operate but I need some clarification. I have some code that starts listening on port 1987 :
Code: Select all
accept connections on port 1987 with message NewConnection
Code: Select all
on NewConnection s
-- when a connection is recevied (this is first set up by mouseUp, above)
-- the "s" variable contains the address and port of the computer that is connecting
-- read in one line of data from the socket identified in the "s" variable
put "NewConnection is called s = " & s & CR after fld "debug"
read from socket s for 1 line
put the result & CR after fld "debug"
--remove any trailing return character
put line 1 of it into tDataMessage
put tDataMessage && "connected" & " on socket " & s & return & return after field "ServerMessages"
-- start reading from the new connection contained in the "s" variable
-- each time more data is received, call the chatMessage handler
read from socket s with message ReadDataMessage
end NewConnection
My first question is where is the parameter "s" described in the documentation? It just seems to appear in the examples.
Code: Select all
on ReadDataMessage s,pdata
-- this handler is called when new data is received from a client
-- it is first set up by the chatConnected handler above
-- the variable "s" contains the host and port of the computer sending
-- the variable "data" contains the text that they sent
-- put the chat message and a new line after the main field
put "ReadDataMessage is called " & CR after fld "debug"
put fld "count" into tCount
add one to tCount
put tCount into fld "count"
put pdata into theData
put the last line of thedata into tdataline
--put thedata & return & return after field "debug"
put "Extracted : " & tdataline & return after field "ServerMessages"
put "End of Message " & return & return after field "ServerMessages"
-- call routines that process the message
-- when more data is received from this client, send this message again
read from socket s with message ReadDataMessage
end ReadDataMessage
- POST / HTTP/1.1
connected on socket 10.0.2.3:42256
Extracted : Test Message from Android
End of Message
POST / HTTP/1.1
connected on socket 10.0.2.3:35194
Extracted :
End of Message
Extracted : ,,,,,0,,,
End of Message
connected on socket 10.0.2.3:38830
POST / HTTP/1.1
connected on socket 10.0.2.3:34989
Extracted : 1343052416,53.463578,-0.785349,50,53.400024,187.237265,-0.926184,7.600154,6.619489
End of Message
POST / HTTP/1.1
connected on socket 10.0.2.3:33094
Extracted : 1343052416,53.463578,-0.785349,50,53.400024,191.090762,-0.503953,6.714831,6.864655
End of Message
Thanks for reading.
Simon