in reply to Re: select() on a client and server socket
in thread select() on a client and server socket

I am writing a chat/instant messaging server.

Normal chat clients connect to the server to chat, so for them I need to create an object to sustain their state, info, etc. The problem is when I try to connect two servers together, so that one server connects to the other and they can pass chat messages across.

Scenario: server1, server2

The admins of server1 and server2 want to join their chat servers, and make it a chat network. Both servers are listening for connections from chat clients. server1 makes a socket connection to server2. This socket will be used to pass chat messages from one server to the other. In this case server1 has to listen on its server socket and the other socket it has created, whereas server2 is only listening on its server socket.

In server1's scenario, I add the connection to the other server to select from inside a Server object.

OK, I know now how to figure out where the data is coming from (server1's server socket or server1's connection socket to server2).

I have this code:

my $select = IO::Select->new($listen); while(1) { my($r,$w) = IO::Select->select($select, $select, undef, 0); my $socket; for $socket (@$r) { ... } for $socket (@$w) { ... }
AFAIK, the above code should block until it comes across a socket that is either readable or writeable.