I just started to learn about networking and follow the book by Kurose and Ross. They have the following snippets of python code to illustrate the UDP protocol.
The code for the simple client is given by
from socket import *
serverName = ‘hostname’ # Use IP adresse here
serverPort = 12000
clientSocket = socket(socket.AF_INET, socket.SOCK_DGRAM)
message = raw_input(’Input lowercase sentence:’)
clientSocket.sendto(message,(serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print modifiedMessage
clientSocket.close()
and the code for the server is given by
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind((’’, serverPort))
print ”The server is ready to receive”
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
serverSocket.sendto(modifiedMessage, clientAddress)
I am lucky to have two laptops and thought about letting one running the client and one the server part. Is this naive? I am struggling to find out how to specify the serverName
variable or IP address here. Both laptops are in the same WiFi network (even though its eduroam which might cause a problem?)
When I use the terminal to find out the local IP addresses one gives me 10.17.47.158 and the other says 100.112.82.103. But just using these IP addresses doesn't seem to work. What am I doing wrong? Also why are they so different, does it mean they are not connected to the same router?
Can I just run both applications on two different laptops and everything should work fine normally when I specify the correct IP address? Or am I getting something completely wrong here?
You have two options
What I would do is follow these steps:
Good Luck!