Inconsistent sockets
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Inconsistent sockets
Hi there,
I've written a program which is a snooker scoring system. I am making two software programs which connect to each other, a scoreboard (client) and the other program is the server. When something happens on a client (a button is pressed to update the score), it writes a single character to the server for what button was pressed. The server then receives the message, puts the character into an invisible field and then through if statements updates the scoreboard it has on it's program. Occasionally, the server doesn't receive the message and doesn't update but if you were to press the same button again it will send. Is this a recurring problem with liveCode sockets or is it just a script error? It doesn't strike me as a script error because it does work, just not every time. Help would be appreciated.
Thanks, Aaron
I've written a program which is a snooker scoring system. I am making two software programs which connect to each other, a scoreboard (client) and the other program is the server. When something happens on a client (a button is pressed to update the score), it writes a single character to the server for what button was pressed. The server then receives the message, puts the character into an invisible field and then through if statements updates the scoreboard it has on it's program. Occasionally, the server doesn't receive the message and doesn't update but if you were to press the same button again it will send. Is this a recurring problem with liveCode sockets or is it just a script error? It doesn't strike me as a script error because it does work, just not every time. Help would be appreciated.
Thanks, Aaron
Re: Inconsistent sockets
Up front I'm going to say I haven't messed with sockets (yet), so much of what I'm about to suggest won't be so I can help you, but so that you can (to some degree) help yourself.agraham147 wrote: ↑Thu Apr 19, 2018 6:44 amIs this a recurring problem with liveCode sockets or is it just a script error? It doesn't strike me as a script error because it does work, just not every time.
The line above that I underlined is usually an indicator of a logic error, not a script or environment error, which you'd probably find in this part of the program.
Usually you can track this down by setting a break point, and stepping through the code line by line to make sure your code is doing what you expect. Be sure to check all variable contents, etc at each step as well. Run through it more than one time, or, if you know what causes failure, start that situation and step through to see where it fails.and then through if statements
Lastly, I'd add that it is a bit hard to answer a question like this without some of the code attached One bonus to attaching it is that sometimes you'll receive advice on how to improve it, not just the answer to the question you asked.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
Ok thanks, I will try what you've suggested.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
Here is some of the code I have. At the bottom I have also included the first if statement for what to do when the message is put into the table1Receiver field to update the scoreboard. As I said before, it works 9/10 but once in a little while it doesn't work. To me it's like the newMessage handler doesn't work everytime a new message comes in because the new message doesn't show in the field and therefore doesn't update the scoreboard through the matchEvent handler. Do I need to do something with my read command?
Code: Select all
on someoneConnected theIP
answer "Table Connected"
read from socket theIP until return with message "newMessage"
end someoneConnected
on newMessage theIP theMessage
put theMessage into field "table1Receiver" of card "multiScoreScreen1"
matchEvent
read from socket theIP until return with message "newMessage"
end newMessage
on matchEvent
local redsRemaining, playerName
--MATCH EVENT FOR "P"
if character 1 of field "table1Receiver" of card "multiScoreScreen1" is "P" then
if the visible field "match1Player1Break" of card "multiScoreScreen1" is true then
set visible of field "match1Player2Break" of card "multiScoreScreen1" to true
set visible of field "match1Player1Break" of card "multiScoreScreen1" to false
put "0" into field "match1Player1Break" of card "multiScoreScreen1"
set foregroundColor of field "match1Player1Points" of card "multiScoreScreen1" to 100,100,100
set foregroundColor of field "match1Player2Points" of card "multiScoreScreen1" to 255,255,255
else
set visible of field "match1Player2Break" of card "multiScoreScreen1" to false
set visible of field "match1Player1Break" of card "multiScoreScreen1" to true
put "0" into field "match1Player2Break" of card "multiScoreScreen1"
set foregroundColor of field "match1Player1Points" of card "multiScoreScreen1" to 255,255,255
set foregroundColor of field "match1Player2Points" of card "multiScoreScreen1" to 100,100,100
end if
end if
-
- VIP Livecode Opensource Backer
- Posts: 9582
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Inconsistent sockets
Before you do anything, test that the message is received.
What I mean by "before you do anything" is to make the server respond immediately after the message
"newMessage" is received. You have sort of done that if you can see if fld "tableReceiver" is updated. But you might do something more dramatic. Anyway, you must determine if the issue resides with the message not being received, and do that way before you process anything.
Craig Newman
What I mean by "before you do anything" is to make the server respond immediately after the message
"newMessage" is received. You have sort of done that if you can see if fld "tableReceiver" is updated. But you might do something more dramatic. Anyway, you must determine if the issue resides with the message not being received, and do that way before you process anything.
Craig Newman
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
Code: Select all
on someoneConnected theIP
answer "Table Connected"
read from socket theIP until return with message "newMessage"
end someoneConnected
on newMessage theIP theMessage
put theMessage into field "table1Receiver" of card "multiScoreScreen1"
#matchEvent
read from socket theIP until return with message "newMessage"
end newMessage
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Inconsistent sockets
Which LC version?
There was a bug in a build or two that prevented "read from socket...until <char>" from working. It has been fixed in v9.0.
There was a bug in a build or two that prevented "read from socket...until <char>" from working. It has been fixed in v9.0.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
I'm using LiveCode 8
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Inconsistent sockets
Is the problem still evident in v9?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
I have now switched to LiveCode 9 and this is my situation at the minute. The client program looks like this:
The server program looks like this:
Now when the client presses P key it changes the player at the table and so this is what the client looks like:
Last edited by agraham147 on Mon Apr 23, 2018 5:19 pm, edited 1 time in total.
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
The client sends a message to the server (the button which was pressed in this case "P"), the server receives it and updates it's scoreboard so now after that the server looks like this:
The next thing to do is to start the clock on the client by pressing the C key. So now the client looks like this:
But the server still looks like this:
As you can see the P is still in the field which means the new message hasn't been received and when I try to press P again it doesn't send that again either, but before I pressed C P worked as many times as I liked. Is this a problem with my read command? By the way, I do have an if statement for C and all the other possible messages just haven't included them in this forum message.
The little black P you see on the grey line is the invisible "receiverField" (visible for this image) which contains the sent message and then through IF statements in a handler called "matchEvent" the program checks to see what letter has been sent, then updates the scoreboard. This is the code for the server program:
Code: Select all
on preOpenStack
set the fullscreenmode of me to "exactFit"
set the fullscreen of this stack to true
accept connections on port 8080 with message "someoneConnected"
end preOpenStack
on someoneConnected theIP
answer "Table Connected"
read from socket theIP until return with message "newMessage"
end someoneConnected
on newMessage theIP theMessage
put theMessage into field "table1Receiver" of card "multiScoreScreen1"
matchEvent
read from socket theIP until return with message "newMessage"
end newMessage
on matchEvent
local redsRemaining, playerName
--MATCH EVENT FOR "P"
if character 1 of field "table1Receiver" of card "multiScoreScreen1" is "P" then
if the visible field "match1Player1Break" of card "multiScoreScreen1" is true then
set visible of field "match1Player2Break" of card "multiScoreScreen1" to true
set visible of field "match1Player1Break" of card "multiScoreScreen1" to false
put "0" into field "match1Player1Break" of card "multiScoreScreen1"
set foregroundColor of field "match1Player1Points" of card "multiScoreScreen1" to 100,100,100
set foregroundColor of field "match1Player2Points" of card "multiScoreScreen1" to 255,255,255
else
set visible of field "match1Player2Break" of card "multiScoreScreen1" to false
set visible of field "match1Player1Break" of card "multiScoreScreen1" to true
put "0" into field "match1Player2Break" of card "multiScoreScreen1"
set foregroundColor of field "match1Player1Points" of card "multiScoreScreen1" to 255,255,255
set foregroundColor of field "match1Player2Points" of card "multiScoreScreen1" to 100,100,100
end if
end if
-
- Posts: 50
- Joined: Thu Apr 19, 2018 6:18 am
Re: Inconsistent sockets
Does anyone know whats going wrong here, would be very much appreciated?