Page 1 of 1

Socket and tsnet

Posted: Tue Feb 18, 2020 4:40 pm
by JakobR
I´m using tsnet to connect to an API with results from rallying (motorsports). At the same time i have asked my program to open a socket waiting for information when the cars passes the goal line.

TSNET
The tsnet connections delivers information in JSON that is transfoRmed to an Array with 50 or so lines. The tsnet-connection is over the internet.

SOCKET
I use port 1100 for the socket command. The message is coming in locally from another software on the same machine (localhost:1100).
The socket connection delivers a string of 15-20 characters.

MY PROBLEM
The tsnet-processes stops the information coming in over the open socket.

How can I work around this? Can I use tsnet to oisten on a port. Or have I missed something?

Jakob Rubenson


CODE: SOCKET
on mouseUp pMouseButton
accept connections on port 11000 with message "clientConnected"
read from socket pSocket with message "messageReceived"
end mouseUp

on clientConnected pSocket
read from socket pSocket with message "messageReceived"
end clientConnected

on messageReceived pSocket, pMsg
put pMsg into theTime
read from socket pSocket with message "messageReceived"
end messageReceived

Re: Socket and tsnet

Posted: Tue Feb 18, 2020 7:18 pm
by LCMark
@JakobR: What tsNet commands/functions are you using? It is possible that the blocking forms of the tsNet API (the Sync) could cause this; so perhaps try the non-blocking (callback-based) ones...

Re: Socket and tsnet

Posted: Fri Feb 21, 2020 7:26 pm
by mwieder
Jakob- is that actual code? You're using port 11000 instead of 1100.
Also, I think the extra lines might cause you trouble.
Possibly use different ports for sending vs receiving?
Maybe something like

Code: Select all

on mouseUp pMouseButton
accept connections on port 1100 with message "clientConnected"
end mouseUp

on clientConnected pSocket
read from socket pSocket until EOL with message "messageReceived"
end clientConnected

on messageReceived pSocket, pMsg
put pMsg into theTime
read from socket pSocket until EOL with message "messageReceived"
end messageReceived

Re: Socket and tsnet

Posted: Sat Feb 22, 2020 11:19 am
by JakobR
Thanks. Will try this.