Receiving data from socket server and hanging in repeat loop
eagletalontim
Posts: 1,399
This was hard to figure a title for So basically, I am trying to send some text to my socket server on my offsite server and receive text back to parse then use. Problem I am having is once the data is received from the socket server, it does not quit the repeat loop to process the other code. Please be aware I am very new to this and am trying to understand / use other code found on the forum.
Basically, all I am trying to do is process other code while waiting for more input from the socket server.
PUB Handle_Wifi | char, i xb.Start(XB_OUT, XB_IN, %0000, 9_600) pause(5000) xb.str(string("Solar Connected!", 13)) ' Server response would be : Solar Connected! : Then : String? repeat i++ if i == 1000 xb.str(string("I am still here!", 13)) i := 0 index~ ' Reset the buffer pointer char := xb.rxtime(10) repeat while char > 31 if char > 31 ' ASCII code of character must be > SPACE buffer[index++] := char ' Append it to the string buffer char := xb.rxtime(10) if char == -1 buffer[index]~ quit char := 0
Basically, all I am trying to do is process other code while waiting for more input from the socket server.
Comments
repeat while char > 31
if char > 31 ' ASCII code of character must be > SPACE
so this never past : char == -1 ..... never quits ....
the rx-method returns -1 if nothing is inside the receivebuffer.
If you can make sure that all your messages come in at once with no delay between the characters you should always get the full messages
This requieres that the size of your receivebuffer is bigger than the longest message
If you don't need to have high speed data-processing you could use rxtime() with a wait-time that is longer as the receiving of the longest message
best regards
Stefan