[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

TCPServer

David Corbin

3/27/2005 11:17:00 PM

Why is TCPServer inheriting from TCPSocket? What methods on it might be used
other than accept, and close?

David


8 Answers

Eric Hodel

3/28/2005 1:15:00 AM

0

On 27 Mar 2005, at 15:17, David Corbin wrote:

> Why is TCPServer inheriting from TCPSocket? What methods on it might
> be used
> other than accept, and close?

A TCP Server is just a socket you called listen(2) on:

To accept connections, a socket is first created with socket(2), a
will-
ingness to accept incoming connections and a queue limit for
incoming
connections are specified with listen(), and then the connections
are
accepted with accept(2). The listen() call applies only to
sockets of
type SOCK_STREAM or SOCK_SEQPACKET.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

David Corbin

3/28/2005 10:24:00 AM

0

On Sunday 27 March 2005 08:15 pm, Eric Hodel wrote:
> On 27 Mar 2005, at 15:17, David Corbin wrote:
> > Why is TCPServer inheriting from TCPSocket? What methods on it might
> > be used
> > other than accept, and close?
>
> A TCP Server is just a socket you called listen(2) on:
>
> To accept connections, a socket is first created with socket(2), a
> will-
> ingness to accept incoming connections and a queue limit for
> incoming
> connections are specified with listen(), and then the connections
> are
> accepted with accept(2). The listen() call applies only to
> sockets of
> type SOCK_STREAM or SOCK_SEQPACKET.

Exactly my point. So why does it inherit from TCPSocket, and more importanly
IO? read, write and all the variations are all not applicable, as far as I
can tell.

David


Yukihiro Matsumoto

3/28/2005 2:19:00 PM

0

Hi,

In message "Re: TCPServer"
on Mon, 28 Mar 2005 19:23:44 +0900, David Corbin <dcorbin@machturtle.com> writes:

|Exactly my point. So why does it inherit from TCPSocket, and more importanly
|IO? read, write and all the variations are all not applicable, as far as I
|can tell.

Just for implementation simplicity, rather than purity.

matz.


Yohanes Santoso

3/28/2005 4:11:00 PM

0

David Corbin <dcorbin@machturtle.com> writes:

> Exactly my point. So why does it inherit from TCPSocket, and more importanly
> IO? read, write and all the variations are all not applicable, as far as I
> can tell.

> On Sunday 27 March 2005 08:15 pm, Eric Hodel wrote:

>> A TCP Server is just a socket you called listen(2) on:

Exactly because it is a TCPSocket. A TCPServer is a TCPSocket with
bound local address(es) (whether it is a specific local address or all
addresses the local host responds to) and thus can be made to listen
to incoming TCP connections on those _bound_ local address(es).

YS.


Kero van Gelder

3/28/2005 4:48:00 PM

0

>> > Why is TCPServer inheriting from TCPSocket? What methods on it might
>> > be used
>> > other than accept, and close?
>>
>> A TCP Server is just a socket you called listen(2) on:
>>
>> To accept connections, a socket is first created with socket(2), a
>> will-
>> ingness to accept incoming connections and a queue limit for
>> incoming
>> connections are specified with listen(), and then the connections
>> are
>> accepted with accept(2). The listen() call applies only to
>> sockets of
>> type SOCK_STREAM or SOCK_SEQPACKET.
>
> Exactly my point. So why does it inherit from TCPSocket, and more importanly
> IO? read, write and all the variations are all not applicable, as far as I
> can tell.

select() works on it, iirc.

+--- Kero ----------------------- kero@chello@nl ---+
| all the meaningless and empty words I spoke |
| Promises -- The Cranberries |
+--- M38c --- http://httpd.chello.nl/k... ---+

David Corbin

3/29/2005 12:58:00 AM

0

On Monday 28 March 2005 11:11 am, Yohanes Santoso wrote:
> David Corbin <dcorbin@machturtle.com> writes:
> > Exactly my point. So why does it inherit from TCPSocket, and more
> > importanly IO? read, write and all the variations are all not applicable,
> > as far as I can tell.
> >
> > On Sunday 27 March 2005 08:15 pm, Eric Hodel wrote:
> >> A TCP Server is just a socket you called listen(2) on:
>
> Exactly because it is a TCPSocket. A TCPServer is a TCPSocket with
> bound local address(es) (whether it is a specific local address or all
> addresses the local host responds to) and thus can be made to listen
> to incoming TCP connections on those _bound_ local address(es).

Is it really a TCPSocket, or is it just a TCP socket. If it's a TCPSocket, I
could do this.

socket = TCPServer('www.google.com', 80)
socket.puts "GET /"

etc. It's not that I think I can't do that (it might actually work for all I
know), but I can't imagine why I would to.



ES

3/29/2005 1:05:00 AM

0


In data 3/29/2005, "David Corbin" <dcorbin@machturtle.com> ha scritto:

>On Monday 28 March 2005 11:11 am, Yohanes Santoso wrote:
>> David Corbin <dcorbin@machturtle.com> writes:
>> > Exactly my point. So why does it inherit from TCPSocket, and more
>> > importanly IO? read, write and all the variations are all not applicable,
>> > as far as I can tell.
>> >
>> > On Sunday 27 March 2005 08:15 pm, Eric Hodel wrote:
>> >> A TCP Server is just a socket you called listen(2) on:
>>
>> Exactly because it is a TCPSocket. A TCPServer is a TCPSocket with
>> bound local address(es) (whether it is a specific local address or all
>> addresses the local host responds to) and thus can be made to listen
>> to incoming TCP connections on those _bound_ local address(es).
>
>Is it really a TCPSocket, or is it just a TCP socket. If it's a TCPSocket, I
>could do this.
>
>socket = TCPServer('www.google.com', 80)
>socket.puts "GET /"
>
>etc. It's not that I think I can't do that (it might actually work for all I
>know), but I can't imagine why I would to.

I don't understand what the deal is here. This is how standard
sockets work. A server is, literally, a socket that's listen()ing
for connections: its input consists of connection requests. In
addition to that, since it's a socket, a server must call socket()
to establish itself, just like a 'client' socket. Therefore it
makes sense for a TCPServer to be a TCPSocket (without it, one
would establish a server by calling TCPSocket#listen). Is this
separation of responsibility causing problems for you?

E



Eric Hodel

3/29/2005 5:19:00 AM

0

On 28 Mar 2005, at 16:58, David Corbin wrote:

> On Monday 28 March 2005 11:11 am, Yohanes Santoso wrote:
>> David Corbin <dcorbin@machturtle.com> writes:
>>> Exactly my point. So why does it inherit from TCPSocket, and more
>>> importanly IO? read, write and all the variations are all not
>>> applicable,
>>> as far as I can tell.
>>>
>>> On Sunday 27 March 2005 08:15 pm, Eric Hodel wrote:
>>>> A TCP Server is just a socket you called listen(2) on:
>>
>> Exactly because it is a TCPSocket. A TCPServer is a TCPSocket with
>> bound local address(es) (whether it is a specific local address or all
>> addresses the local host responds to) and thus can be made to listen
>> to incoming TCP connections on those _bound_ local address(es).
>
> Is it really a TCPSocket, or is it just a TCP socket. If it's a
> TCPSocket, I
> could do this.
>
> socket = TCPServer('www.google.com', 80)
> socket.puts "GET /"

Would that make sense for the UNIX implementation of sockets? No.

You'll probably get an ENOTCONN back because you haven't connected your
socket to anything.

> etc. It's not that I think I can't do that (it might actually work
> for all I
> know), but I can't imagine why I would to.

Then why do you care?

Like a Socket you can call:

#addr, #getsockopt, #setsockopt, #shutdown

You can also IO::select a server socket.

Like an IO you can call:

#fcntl, #close, #close_read, #close_write, #closed?, #fileno

I think that's more than enough reason to make it a subclass of
TCPSocket, rather than try to break the shared functionality of regular
sockets and server sockets (and IOs) into common code only to recombine
them again.

I'd rather use some handwavium and subclass. Sounds far more
convenient.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04