Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 523817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:30:07+00:00 2026-05-13T08:30:07+00:00

I have two simple Python files: client.py and server.py . The client simply sends

  • 0

I have two simple Python files: client.py and server.py. The client simply sends the text you type to the server, via UDP socket.

The port assigned and listened to is 21567, BUT… the line reading:

print "\nReceived message '", data,"' from ", addr

in server.py outputs the addr to be something looking like this: (‘127.0.0.1’, 60471)

Now I don’t understand why this seemingly random port is reported, the 60471 is random everytime the script is run. Can anyone please shed some light on this matter, why is it not saying 21567 like set in the code? Thanks!

The Python script file contents are as follows:

client.py

# Client program

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "\n",def_msg

# Send messages
while (1):
    data = raw_input('>> ')
    if not data:
        break
    else:
        if(UDPSock.sendto(data,addr)):
            print "Sending message '",data,"'....."

# Close socket
UDPSock.close()

server.py

# Server program

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
    data,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has exited!"
        break
    else:
        print "\nReceived message '", data,"' from ", addr

# Close socket
UDPSock.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:30:07+00:00Added an answer on May 13, 2026 at 8:30 am

    60471 is the client’s port and 21567 is the server’s port. They can’t be the same: Any IP traffic has to declare its source address and port, and its destination address and port. The client port is usually a random number in the range 32768 to 65535. addr is telling you the client’s address.

    This is done so you can have multiple clients talking to the same server (i.e. IP address and port combination), and the streams can be disambiguated using the client port numbers, even with a connectionless protocol like UDP/IP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Python 2.6.1 on Mac OS X. I have two simple Python files (below), but
I am setting up a simple test page in Python. I only have two
I have these two simple files that define a C++ class with a tryME
I have two utilities written in C++, TCP/IP server and client that I have
I have started to write a Python 3.x client application. The server application exists
Ok, so basic python question. I have a simple script to replace text on
I have two simple submit buttons on my form, which work just fine: <button
Let's say I have two simple models project t.string :title vote t.references :project t.integer
I have two very simple routes routes.MapRoute( post, // Route name postPage + /{slug},
I have two relatively simple codes. One main activity and one intent service. Main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.