I am trying to establish a TCP socket between my linux server and my client running on my laptop. The TCP server code I am running is,

from socket import *

    HOST = ''
    PORT = 1999
    serversocket = socket(AF_INET,SOCK_STREAM)
    while True:
        (clientsocket, address) = serversocket.accept()
        print ("Got client request from",address)
        clientsocket.send("Thank You for connecting")

The TCP client code I am running is :

from socket import *

clientsocket = socket(AF_INET,SOCK_STREAM)


recv = clientsocket.recv(1024)


The problem I am facing is that I am not able to communicate with the server from my client. WHen I run both the TCP client and server code on my linux server, the communication works. So, I have narrowed down this issue to lack of open TCP ports on my server. I am using windows 8 on my laptop. I did an nmap from my laptop to my server and the list of open ports available were, 80/tcp, 443/tcp,22/tcp. So, can anyone suggest on how to add a port to the list of open ports. For example, in this case I need to add 1999 to the list of open ports.

Server version: Linux hostname 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

  • 1
    What firewall are you using? If it's ufw, try the command sudo ufw allow 1999/tcp – s3lph Mar 29 '15 at 14:48
  • 1
    Your example server code works better with Python 2.7 than it does with Python 3. You should probably say what version of Python you use. – Bruce Ediger Mar 29 '15 at 16:34
  • @BruceEdiger Using 2.7 – bhuvan Mar 29 '15 at 16:53
  • You could add exception handling to print where and why this is failing. You can also test connectivity to many servers with telnet specifying an explicit port. – bsd Mar 30 '15 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.