Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneral Python socket questions with several answers
    primarykey
    data
    text
    <p>I am trying to use <a href="http://www.devshed.com/c/a/Python/Sockets-in-Python/2/" rel="nofollow noreferrer">an example</a> for a server, but the client can only send one message and then the server will reply with a number.</p> <p>Here is the code.</p> <pre><code>import socket mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) mySocket.bind ( ( '', 2000 ) ) mySocket.listen ( 1 ) while True: channel, details = mySocket.accept() print 'We have opened a connection with', details print channel.recv ( 100 ) channel.send ( 'Green-eyed monster.' ) channel.close() </code></pre> <p><strong>Questions:</strong></p> <ol> <li><p>Why is it that whenever the client sends a message to the server, it responds with a number?</p></li> <li><p>How can I use sockets over the Internet, not over LAN?</p></li> <li><p>Is there a way for me to have the server move data from client to client using sockets - somewhat like an <a href="http://en.wikipedia.org/wiki/Instant_messaging" rel="nofollow noreferrer">IM</a> program.</p></li> <li><p>I will most likely host this IM server for my friends on my Mac - will it work between OS's (Mac, PC)</p></li> <li><p>Are there any good libraries to use for this? (I have heard that HTTP is great)</p></li> <li><p>These lines of code are <em>really</em> confusing. How do they work?</p> <pre><code>print channel.recv ( 100 ) channel.send ( 'Green-eyed monster.' ) </code></pre></li> <li><p>Also, when I close the server (using the red X), and reuse the port, it says this:</p> <pre><code>Traceback (most recent call last): File "C:\Users\****\Desktop\Python\Sockets\First Server\server.py", line 3, in &lt;module&gt; mySocket.bind ( ( '', 2003 ) ) File "C:\Python27\lib\socket.py", line 224, in meth return getattr(self._sock,name)(*args) error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted </code></pre></li> <li><p>Lastly, where are some good tutorials for me to understand this better?</p></li> </ol> <p>Sorry for asking so many questions in the same post, but when I posted <a href="https://stackoverflow.com/questions/14764294/how-to-change-the-shutdown-message-for-windows-using-python">this</a> and <a href="https://stackoverflow.com/questions/14764126/how-to-make-a-python-script-which-can-logoff-shutdown-and-restart-a-computer">this</a> people got mad with me for posting about similar problems in different problems.</p> <p>Python version: Python 2.7.3</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload