Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code works fine I've made some minor corrections though and explained them in comments inside the code:</p> <p><strong>SERVER:</strong></p> <pre><code>import socket from thread import * # 1.Gets the local ip/ip over LAN. HOST =socket.gethostbyname(socket.gethostname()) print HOST # 2.Use port no. above 1800 so it does not interfere with ports already in use. PORT =input ("Enter the PORT number (1 - 10,000)") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM ) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) print "Socket Created" s.bind((HOST, PORT)) print "Socket Bind Complete" s.listen(10) print "Socket now listening" while True: connection, addr = s.accept() print "Connection Established!" connection.send("Welcome to the server. Type something and hit enter\n") while True: data = connection.recv(1024) if not data: break connection.sendall(data) print data connection.close() s.close() </code></pre> <p><strong>CLIENT:</strong></p> <pre><code>import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print "Socket Created" host = raw_input("HOST &gt;&gt;&gt; ") # 3. Use the same port no. entered on server.py as the client binds to the # same port port = input ("Enter the PORT number (1 - 10,000)") s.connect((host, port)) while True: message = raw_input("&gt;&gt;&gt; ") s.sendall(message) reply = s.recv(1024) print reply </code></pre> <p>The above code just worked fine for me, I'm sure it would for u too as I've experienced the same trouble. The bugs found I've put them in the comments inside the code take a look.</p> <p>Cheers ....! </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.
    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