Shop OBEX P1 Docs P2 Docs Learn Events
Receiving data from socket server and hanging in repeat loop — Parallax Forums

Receiving data from socket server and hanging in repeat loop

eagletalontimeagletalontim Posts: 1,399
edited 2015-01-29 13:37 in Propeller 1
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.
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

  • LtechLtech Posts: 380
    edited 2015-01-26 23:26
    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.
    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.

    repeat while char > 31
    if char > 31 ' ASCII code of character must be > SPACE

    so this never past : char == -1 ..... never quits ....
  • eagletalontimeagletalontim Posts: 1,399
    edited 2015-01-27 14:21
    So basically I can change the "repeat while char > 31" to "repeat while char > -1"? I am worried that only part of a string will be returned and it will mess up my data parsing.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-01-29 13:37
    How about sending a special "End-of-Message" character?

    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
Sign In or Register to comment.