Page 1 of 1

Socket Communication Confusion

Posted: Sat Apr 30, 2011 4:01 am
by dglass
Greetings,

I'm a bit confused about socket comms in LC, and am hoping somebody can clear it up for me.

Given the following

Code: Select all

on mouseUp
   global strSocketConnection
   
   if label of button "Connect" is "Connect" then
   put strServerName & intLobbyPort into strSocketConnection
   
   open socket to strSocketConnection --with message "connected"
   write "*LOGIN::username::password" to socket strSocketConnection
   set label of button "Connect" to "Disconnect"
   read from socket theHost until crlf with message "readSomething"
else
   close socket strSocketConnection
   set label of button "Connect" to "Connect"
end if

end mouseUp

--currently not called for debugging
on connected theHost
   --connected so login
   write "*LOGIN::username::password" to socket theHost
   set label of button "Connect" to "Disconnect"
   read from socket theHost until crlf with message "readSomething"
end connected

on readSomething theHost theMessage
   if theMessage is not empty then
      put theMessage after field "ChatLog"
   end if
   
  read from socket theHost until crlf with message "readSomething"
end readSomething
I'm able to properly open the socket and login (username shows up in list of users), but the 'read from ...' command never kicks out to the 'readSomething' handler, which it should do because of the 'with message' portion (right?).

In a previous incarnation I had this working, but accidentally deleted the button, and 'Undo' didn't, so am recreating from a less than stellar memory.

In the previous iteration I was able to get it into the 'readSomething' handler but it never called itself again which is what should happen given the 'read from...with message' command at the end, right?

I have no doubt this is something simple, but I'm still missing it.

Re: Socket Communication Confusion

Posted: Sat Apr 30, 2011 4:11 am
by dglass
Aaaannndddd, 20 seconds after posting, I figured it out.

I am Jack's complete lack of surprise.

This:

read from socket strSocketConnection with message "readSomething"

not this:

read from socket strSocketConnection for/until <whatever> with message "readSomething"