Ryan Davis
1/22/2009 11:54:00 PM
On Jan 22, 2009, at 14:43 , Kamaljeet Saini wrote:
> I have this following code that able to make connection and then
> disconnect. But after doing connection, i wish to receive data before
> doing disconnect. Im very new to understand socket programming will be
> great to get some help here.
>
> require 'socket'
> streamSock = Socket::new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
> myaddr = [Socket::AF_INET, 5555, 113, 129, 2, 162, 0,
> 0].pack("snCCCCNN")
> print "connecting...\n"
> streamSock.connect( myaddr )
> print "connected\n"
>
> # How to read/receive data ( sample code example will help )
>
> print "disconnecting...\n"
> streamSock.close
> print "disconnected\n"
The Socket section in the pickaxe is a good place to start. pg 714.
ri Socket.connect
ri Socket.accept
also:
ri TCPServer
much better way to go if you're able to go high level (and are writing
the server side of things as well)