I want to make a python script run on a socket of server in LAN. I wrote a number guessing script and i want to make it run on socket for other clients to play with it by connecting to port (say 1234). I know to achieve this by socket programming from python. But this question is to ask as to why this fails?

ncat -lvp 1234 -e /usr/bin/python3.5 number_game.py

the script:

import random
print("Welcome to the game...")
for i in range(1,7):
    print("Take a guess")
    if guess > num:
        print("Way too high")
        if guess < num:
            print("Way too low")
if flag == 1:
    print("You made it in "+str(i)+" attempts")
    print("better luck next time")

the error:

Ncat: Version 7.31 ( https://nmap.org/ncat ) Ncat: Got more than one port specification: 1234 number_game.py. QUITTING.

  • The manpage says: ncat [OPTIONS...] [hostname] [port]. You should surround your command with quotes: -e '/usr/bin/python3.5 number_game.py', as otherwise number_game.py is inerpreted as port number (see the error message). – ridgy Jan 2 '17 at 12:05


You are trying to listen on the port 1234, and to connect to machine with the IP in the same time.

You can't do that, you either listen for the connection using this :

ncat -lvp 1234 -e "/usr/bin/python3.5 number_game.py"`

or you initiate the connection to the desired machine using this :

ncat -v -e "/usr/bin/python3.5 number_game.py" 1234


When you use ncat (or nc) to initiate the connection, you have to keep the IP (or hostname) and the port the last parameters.

Look to the synopsis of ncat in the manual : ncat [OPTIONS...] [hostname] [port]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.