1

So I have this python server which just returns the uppercase sentence which came as a input:

from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('192.168.1.2', serverPort))
print "The server is ready to receive on port: {}".format(serverPort)
while 1:
    message, clientAddress = serverSocket.recvfrom(2048)
    print clientAddress, message
    modifiedMessage = message.upper()
    serverSocket.sendto(modifiedMessage, clientAddress)

From this client:

from socket import *

serverName = "192.168.1.3"
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = raw_input("Input lowercase sentence:")
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print modifiedMessage
clientSocket.close()

Everything works as expected on localhost but when I execute server.py on one machine and run client.py on another machine the client is unable to contact server.py.
Furthermore I can't even connect to server.py via telnet on the same machine where server.py is running) Here's the traceback:

Connecting To 192.168.1.2...Could not open connection to the host, on port 12000: Connect failed 

Now I sniffed some packets using Wireshark and surprisingly, the protocol against this packet was LLC instead of UDP and the data field was:

Data: 74:5f:32:20:61:6e:64:72:6f:69:64
[Length: 11]

I apologize if the difference is trivial, but I have just started socket programming and it's bugging me.

3
  • As far as I know, telnet doesn't do UDP. Do you have a firewall running on the server machine?
    – Jukka
    Commented Dec 13, 2015 at 19:55
  • @Jukka Nope, I disabled it. I can access Apache server running on the same machine as server.py from other clients on LAN
    – Jarwin
    Commented Dec 13, 2015 at 19:57
  • Are you binding server.py to the appropriate IP address?
    – Jukka
    Commented Dec 13, 2015 at 20:02

1 Answer 1

2

Firstly, SOCK_DGRAM is UDP so you won't be able to use telnet because it's TCP only.

The packets are UDP. I expect that wireshark is just mistaking them for LLC because of the port 12000 (LLC runs on top of UDP I believe).

It looks like this isn't working because you've set serverName to .3 in the client script but the server is listening on .2.

I'll also just ignore the camel casing in Python ;)

3
  • Would you be so kind as to provide me some additional details on this line from your answer: ...LLC runs on top of UDP... I was under the impression that port 12000 was free?
    – Jarwin
    Commented Dec 13, 2015 at 20:11
  • Also, it might be a very trivial difference and you might be give yourself a facepalm when you read it, but, if I am not wrong, I am not following the HTTP protocol, right? But there is a request response cycle?
    – Jarwin
    Commented Dec 13, 2015 at 20:14
  • HTTP is quite different; it's a higher level protocol built on top of TCP. What you're doing is simple request -> response but over raw UDP. As for the ports, you're free to use any port that you like - just wireshark seems to think that LLC often uses that port... Actually it's assigned to an IBM protocol which you'll see here: iana.org/assignments/service-names-port-numbers/… Commented Dec 13, 2015 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .