Getting no response from socket server

Hello,

I have some problems programming a socket client that send order to RIOS’ socket server.

When I send a request to the socket server, it receives the request, but send nothing, though I wait for an answer. But I can still receive the echo signal when the option is enabled.

here are some of my code :

From the RIOS socket server log, if echo is enabled, I get :

and then nothing.
How should I receive information from RIOS ? Because, unless I relaunch RIOS, it won’t accept any other message after the first one, which is big problem for me.

Thanks if you can help me.

Hello Zaldor,

Does it work using Socket client Demo program?
Does clicking on “Refresh” fill the Demo program comboboxes ?
if no maybe RIOS is not in the “Play” form.

RIOS must be in the “Play” form to answer commands about projects, like “project:list” else it returns nothing.

You should use the command “” at first, if RIOS return “Error” it means it’s not in the “Play” form, and so it will not answer commands about the projects.

I’m talking about this in the manual page 27, 10th line, but yes it needs to be clearer, this line is important but burried in tons of text sorry, i will modify the manual to copy this information in the commands list, the best place i think.

Laurent

Thank you for your answer. I was indeed testing my program while watching the log file, so I wasn’t in the “play” window.

But my troubles are not over though…

Now I can send an order and get the answer, but when I send a second order, it only receives the first character.

something like this

And it’s the same for any order I send afterwards, unless I relaunch the RIOS (deactivate/reactivate the server won’t do anything about it).

Is there something more to do than send and receive messages with my socket client ? Because I really don’t understand why the RIOS server won’t receive any order after the first one, which blocks al my work for now.

The demo is working okay, but I don’t use the same library.

I use winsock library, and here is my code for the communication:

char sendbuf1[256] = “project:selected”;
send(sock, sendbuf1, 256, 0);
char recvbuf1[256] = “”;
recv(sock, recvbuf1, 256, 0);
if (recvbuf1 != “ViKi”)
{
char sendbuf2[256] = “<project_select:ViKi>”;
send(sock, sendbuf2, 256, 0);
char recvbuf2[256] = “”;
recv(sock, recvbuf2, 256, 0);
}
send_sequence(sock, seq);
send_step(sock, step);

As I said, RIOS will only receive the first message "project:selected, and return the project. Then, whatever I send to it, it will only receive “<” (several time in a row if I send several messages).

Hello Zaldor,

you should not send “256” char to RIOS if you only need to send 21,
else RIOS will have to deal with 235 unwanted char, and maybe some of them are “<” and RIOS is waiting the according “>” till the timeout.

you can’t use socket so simply as using “send” / “recv”, a socket is more complex,
to send it’s ok, just use “send” but only send the correct number of char needed, not a full 256 bytes buffer filled with char that RIOS don’t need.
Adding to this you should always clear the outgoing AND the incoming buffer (not your buffer but the socket one) before sending new fresh data

To read it’s more complex, a socket will not send to you the full bytes you need in a row in many cases (not RIOS fault).
To correctly read a socket :

  • You should use a read event, this way the main code is able to run, and it will be interrupted only if incoming datas are coming and will execute the “read event” part of the code.
    if you don’t use an event it will work but the code will be more difficult to build and your program will hang while waiting full data from the socket.

  • you’ll have to check for incoming “" char meaning RIOS is answering something, then you need to find in the buffer (not in the full 256 bytes buffer you’re using but only in the fresh new bytes) the other "” finishing the “word” that RIOS sent
    use the “int” returned by the recv function to know how many bytes received from RIOS thru the socket and use this value in a "for " loop to scan your buffer.
    if no second “" was found, store the current fresh bytes in another buffer and read again to have more bytes till you get the second "” this way you will always get full word from RIOS.
    it’s not a RIOS issue, RIOS is sending all datas at a time but the socket is working in a different way, cutting some data in blocks…or not.

That’s why RIOS is sending how many lines will be send when you ask “xxx:list” this way, extracting the number in the "Count:xxx) text line you know how many lines you need to read after the “count” one.

you should take a look at the small demo program code (*.cpp files)
it’s C++ but it’s the way you should read a socket that you may inspire yourself from the code, not really the code itself as it’s different.

Basically when i send an order to RIOS i’m initializing an “int” variable for the Read event to know what kind of answer it will receive ( a list, a message to display, a simple word etc…) then when datas are incoming from RIOS it interrupts the program and it goes to the read event that build complete “word” checking for “" couples in the flow, checking if a “count” word is in (if waiting a list) and then read “count” line and store them…then it really do something according to RIOS answer only when all data are read, cut in words using the "” couples and stored in a clean “lines” (AnsiStringList) buffer (not the read buffer)

if i need to lock the program buttons while waiting an answer from RIOS (to avoid sending too much information and generate data colision) i’m setting the buttons “activated” property to “false” then to “true” when ready again.

The main problem i had to deal with when building the socket demo program was the “read algorithm”, you will see what i mean if you look in the code (the tips to understand the code is to know the “read” event code is running automatically when incoming data occurs)

then you need to use a timeout (see my code) to stop waiting after 1 or 2 seconds.

i hope it help.

Hello again,

Yes, it helped a lot, since I managed to communicate successfully with RIOS. You were right, it was mostly a problem with the buffers’ size.

Now that my project works, I’m so releaved.

Thank you for the help !

Wait, show us your project! :smiley:

Sure !

I don’t have videos for now, but I’ll make one this week.

For a small presentation : there’s a software that was developped by previous students (ViKi : Virtual Interactive Keyboard Interface) that analyses the images from my webcam. With that, I can move a cursor on the screen by moving my hand (my hand is used like a mouse, in a way).

Then I made a simple interface that send orders to RIOS to move the robot when I move my hand.
=> I move the robot with my hand thanks to a webcam. It’s funny to use.

I’ll send the code (it’s open source, but you need RIOS) and a video if you’re interested.

Sounds really fun. Yeah, we’re interested to here more about this! 8)