Re: Communicating with a servlet using NIO?



On Thu, 06 Dec 2007 05:42:28 GMT, Esmond Pitt
<esmond.pitt@xxxxxxxxxxxxxxxxxx> wrote:

George Neuner wrote:

constantly in a busy system. Not only do most programs let the system
select outgoing ports, but the system also selects the incoming ports
for most server programs.

This is not correct. TCP/IP uses the same port number as the listening
port for incoming connections.

When a connection is made to a TCP
listen port, the system selects a free port and transfers the incoming
connection to it - all communication beyond the initial connection by
the client takes place through that randomly assigned port.

This is not correct. See above.

Sorry, but it is you who are wrong. Look in your help or man pages
for the description of the "accept" call.

You may be thinking that sockets can be shared and multiplexed - which
is true - but that's not how the accept call works.


<QUOTE> from FreeBSD man page accept(2)
Accept removes the next connection request from the queue (or waits
until a connection request arrives), creates a new socket for the
request, and returns the descriptor for the new socket. Accept only
applies to stream sockets (e.g., those used with TCP).
<\QUOTE>

<QUOTE> from Linux man page accept(2)
The accept() system call is used with connection-based socket types
(SOCK_STREAM, SOCK_SEQPACKET). It extracts the first connection
request on the queue of pending connections, creates a new connected
socket, and returns a new file descriptor referring to that socket.
The newly created socket is not in the listening state. The original
socket sockfd is unaffected by this call.
<\QUOTE>

<QUOTE> from Winsock2 SDK
The accept function extracts the first connection on the queue of
pending connections on socket s. It then creates and returns a handle
to a new socket. The newly created socket is the socket that will
handle the actual connection; it has the same properties as socket s,
including the asynchronous events registered with the WSAAsyncSelect
or WSAEventSelect functions.
<\QUOTE>


I don't have an AT&T Unix derivative handy to quote from its man page.
The basic TLI calls are similar to BSD in that t_listen sets the
connection point to passive mode and t_accept creates and returns a
new stream endpoint. The details are different because TLI allows
compositions of streams and filters in a way that's very similar to
the way Java handles streams.


In 20+ years I've worked with a half dozen versions of Unix, with
Linux, with MacOS (before the Unix versions), with every version of
Windows and with three different RTOS's. I've never encountered any
TCP implementation in which accept did not create a new socket.

George
--
for email reply remove "/" from address
.



Relevant Pages

  • Re: Definition of a socket on Suns website
    ... the server gets a new socket bound to a different port. ... It needs a new socket (and consequently a different port number) so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client. ...
    (comp.lang.java.programmer)
  • Re: Socket and cycle problem
    ... listening this port countinously. ... So I need make some loop to print data from 3883 port permanent. ... the data it receives from each connection after the remote side drops ... If you were to use the socket module, then it would look something like this: ...
    (comp.lang.python)
  • Re: fork + socket -server fails
    ... If I use from either Expect or Tclx in combination with [socket ... On FC-4 I can telnet to port ... 8015 and the script prints out the expected "Accepted connection:" ... puts "Accepted connection: $args" ...
    (comp.lang.tcl)
  • Re: PPP server using a port for connection
    ... inetd detects the incoming call and runs the ... accepted socket. ... When RAS finds an available modem, he opens a socket connection to ... > the server to port, for example, 9090. ...
    (comp.protocols.ppp)
  • Re: Socket class, connect to an endpoint with port 21
    ... It seems that you might have a FTP proxy server soemwhere in between. ... I'm developing a FTP Client using the socket class. ... to verify the connection I always use the Socket.Connected var. ... it always connects if the remote Endpoint uses the port ...
    (microsoft.public.dotnet.languages.csharp)