Socket and tsnet

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JakobR
Posts: 2
Joined: Tue Feb 18, 2020 4:33 pm

Socket and tsnet

Post by JakobR » Tue Feb 18, 2020 4:40 pm

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

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: Socket and tsnet

Post by LCMark » Tue Feb 18, 2020 7:18 pm

@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...

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Socket and tsnet

Post by mwieder » Fri Feb 21, 2020 7:26 pm

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

JakobR
Posts: 2
Joined: Tue Feb 18, 2020 4:33 pm

Re: Socket and tsnet

Post by JakobR » Sat Feb 22, 2020 11:19 am

Thanks. Will try this.

Post Reply

Return to “Internet”