04-08-2023 09:35 AM
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.
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))
04-08-2023 01:03 PM
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)...
04-08-2023 01:20 PM - edited 04-08-2023 01:28 PM
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.
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.
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.
04-08-2023 01:38 PM
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 ?
04-08-2023 01:40 PM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide