Connect and handle multiple raw sockets at once in Python 2.x
<p>I am new to Python, and trying to learn it "on the job". And I am required to do this.</p>

<p>I am required to communicate with 3 servers with a raw socket connection. I can easily do that in a sequential manner. But I was wondering if there is a way I can communicate with these 3 servers at once? All 3 servers have different IP addresses. </p>

<p>Basically try to do the following but in 1 step:</p>

<pre><code>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST1, PORT1))
s.connect((HOST2, PORT1))
s.connect((HOST3, PORT1))
</code></pre>

<p>which is also need later <code>s.sendall()</code> &amp; <code>s.recv()</code> to be parallelized. </p>

<p>It's hard to prescribe a wealth of knowledge without knowing more information about your server protocol, what you are listening for and what you intend to do with it, et-c, but I can imagine, given no other additional information, a scenario where the communication is handled by a multiprocessing.Pool(3) where each member of the pool is mapped to an IP address and where all three send data into the same multiprocessing.Queue () which is being evaluated by a loop thread.</p>

<p>Any additional details?</p>

<p>Best of luck on your job!</p>

python multithreading sockets multiprocessing raw-sockets