Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: select() on a client and server socket

by amir (Sexton)
on Jul 11, 2001 at 20:49 UTC ( [id://95759]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://95759]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found