Question

I am using this line to send a message via a Ruby (1.8.7) socket:

@@socket.send login_message, 0

(This works fine)

What is the second parameter for? I can't find the send method in the Ruby API docs...

I first thought that it was some C style length of the message. This is why I used login_message.length as second parameter. That worked but I encountered a strange behavior:

Everything works fine when the second parameter is a odd number. If it's an even number the last character gets lost at receiving on the other side (The other side is a C++ program with a C socket). I inspected the network traffic with Wireshark and noticed that the packets look good. All the data is complete. Why is the last character lost when I receive it?

Thank you Lennart

Was it helpful?

Solution

This is the flags parameter, the same as the last parameter to the send() system call. Normally it should be 0, but may be something like Socket::MSG_OOB (to send out-of-band data). For Ruby 1.9 this is documented under BasicSocket.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top