cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
719
Views
0
Helpful
4
Replies

UDP Python Communication

Kevin18
Level 1
Level 1

Hello,

I have an assignment about a simple UDP Communication.

One of the task is "Show the clients’ IP addresses and port numbers on the server and vici versa." There is also a picture about the UDP Communication.

I get my IP with ipconfig but I don't know how to get my port. I tried with netstat -a but I don't know which port. In the picture, there are many port like 499999, 60000, 59999, 50000. How can I know which port to choose.

Kevin18_2-1680971693980.png

Here is my server.py

import socket

UDP_IP = "192.168.0.17"
UDP_PORT = 5005

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
sock.bind((UDP_IP, UDP_PORT))

while True:
  data, addr = sock.recvfrom(1024) 
  print("received message: %s" % data)

Here is my client.py

import socket

UDP_IP = "192.168.0.17"
UDP_PORT = 5005

print("UDP target IP: %s" % UDP_IP)
print("UDP target PORT: %s" % UDP_PORT)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

while True:
    data = input("Enter a word: ");
    sock.sendto(data.encode("utf-8"), (UDP_IP,UDP_PORT))

 

4 Replies 4

Hello,

what is the context of your question ? You need to explain to us what exactly you are doing, and what you are after. Are you looking for a Windows/DOS command to display a specific UDP port ? 'netstat -b' tells you which application uses which port (you need to run this as administrator)...

Hello,

sorry I am not very good at explaining. Now, I am very confused what this picture mean. I have a server (run on VM) and a client(my computer). First I start the server.py on my VM then I switch over to my computer and run client.py.

The result is a simple udp communication and I think that it is working.

Kevin18_2-1680985338569.png

 

In my script I define my UDP port as 5005(a random number). The picture is very confusing for me because there are 4 port(49999, 60000, 59999, 50000). But for my program to work I have to use the same port.

Kevin18_0-1680984762262.png

Edit: I think I have to run my server.py on my VM and host. For example the VM get the port 60000 and my computer get the port 50000. Now I am trying to figure out which port my IP is.

Hello,

to be honest, I do not see either how that picture is related to your task. Do you have a link to the task, or can you post the complete task ?

Hello,

this is my assignment and I am currently working on task 2. task 1 i skipped because I need the ip and port

Kevin18_0-1680986408912.png

 

Review Cisco Networking for a $25 gift card