how to set socket options?

N

Nasir Khan

[Note: parts of this message were removed to make it a legal post.]

We can set socket options using setsockopt on BasicSocket, where can I get
various constants SOL_ constants such as Socket::SOL_SOCKET etc?
I am unable to find them in rdoc.

Also while writing a TCP client to a non Ruby (but non blocking) server
while I write on the socket using socket.write <string> I am not getting
anything on the server till I do socket.close.
socket.puts <string> works fine but has an additional newline in the message
which I do not want.

Any pointers in both of these questions will be greatly appreciated.

Thanks
Nasir
 
G

Gary Wright

Also while writing a TCP client to a non Ruby (but non blocking)
server
while I write on the socket using socket.write <string> I am not
getting
anything on the server till I do socket.close.
socket.puts <string> works fine but has an additional newline in
the message
which I do not want.

Try socket.flush. It seems like your socket is line buffered. I'm not
sure how Ruby decides on buffering and there doesn't seem to be an
interface to something like setvbuf. Perhaps someone else can provide
some insight.

One thing to keep in mind when using TCP is that message boundaries
are not preserved. A write on one end of a TCP socket does not
necessarily
map to a corresponding read with the same data on the other
end of the socket.

Gary Wright
 
N

Nasir Khan

[Note: parts of this message were removed to make it a legal post.]

I tried socket.flush it doesnt work either. The reason I asked for socketopt
options is I wanted to try enabling TCP_NODELAY.
 
H

hemant

We can set socket options using setsockopt on BasicSocket, where can I get
various constants SOL_ constants such as Socket::SOL_SOCKET etc?
I am unable to find them in rdoc.

I am afraid, RDoc won't have an exhaustive list of these constants.
However, for all such purposes, I have Richard Stevens book on network
programming book and you can find them listed there.
Also while writing a TCP client to a non Ruby (but non blocking) server
while I write on the socket using socket.write <string> I am not getting
anything on the server till I do socket.close.
socket.puts <string> works fine but has an additional newline in the message
which I do not want.

As for disabling naggle algorithm you can use:

t_sock_addr = Socket.sockaddr_in(port,ip)
t_socket.setsockopt(Socket::IPPROTO_TCP,Socket::TCP_NODELAY,1)

Also problem you mention shouldn't have anything to do with flush or
naggle algorithm.
Probably, your server is using newline as message separator in which
case. But this is just a wild guess.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top