[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to set socket options?

Nasir Khan

2/29/2008 12:54:00 AM

[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

3 Answers

Gary Wright

2/29/2008 3:53:00 AM

0


On Feb 28, 2008, at 7:53 PM, Nasir Khan wrote:
> 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

Nasir Khan

2/29/2008 4:13:00 AM

0

[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.

On Thu, Feb 28, 2008 at 10:52 PM, Gary Wright <gwtmp01@mac.com> wrote:

>
> On Feb 28, 2008, at 7:53 PM, Nasir Khan wrote:
> > 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
>
>

hemant

2/29/2008 4:50:00 AM

0

On Fri, Feb 29, 2008 at 6:23 AM, Nasir Khan <rubylearner@gmail.com> wrote:
> 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.