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

  • SEARCH
  • Home
  • 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 8162111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:38:19+00:00 2026-06-06T18:38:19+00:00

I am trying out an example from the book Foundations of python network programming,

  • 0

I am trying out an example from the book Foundations of python network programming, which lists a simple UDP client/server program. The first program had the client/server within the same machine, but the second one has the server listening for any machines. The book does not detail on how to establish a connection between two machines.

I have two computers which are both connected to the internet. How can I configure them to send and receive packets from each other.

Here is the source code from the example:

#!/urs/bin/env python
# UDP client and server for talking over a network

import random, socket, sys

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

MAX  = 65535
PORT = 1060

if 2<= len(sys.argv) <= 3 and sys.argv[1] == 'server':
    interface = sys.argv[2] if len(sys.argv)>2 else ''
    s.bind((interface,PORT))
    print 'Listening at ', s.getsockname()
    while True:
        data, address = s.recvfrom(MAX)
        if random.randint(0,1):
            print 'The client at ', address, 'says:', repr(data)
            s.sendto('Your data was %d bytes ' % len(data) ,address)
        else:
            print 'Pretending to drop packet from ', address


elif len(sys.argv)==3 and sys.argv[1] == 'client':
    hostname = sys.argv[2]
    s.connect((hostname,PORT))
    print 'Client socket name is', s.getsockname()
    delay = 0.1
    while True:
        s.send('This is another message')
        print 'Waiting up to', delay, 'seconds for a reply'
        s.settimeout(delay)
        try:
            data = s.recv(MAX)
        except socket.timeout:
            delay *= 2 # wait even longer for the next request
            if delay > 2.0:
                raise RuntimeError('I think the server is down')
        except:
            raise # a real error so we let the user see it
        else: 
            break
    print 'The server says ', repr(data)

I found out the public IP of the computer running as server, and tried to connect to it from another machine running as client, but I didn’t get response. I am not behind a proxy in either computers.

  • 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-06-06T18:38:20+00:00Added an answer on June 6, 2026 at 6:38 pm

    To start, if you really want to try such application and learn, you would need to have these two machine connected on a local network within same subnet so each machine have address like 192.168.x.2 and 192.168.x.2, this way you will know what is happening…

    Then when you run above application in one machine run as “_application_name server” and on other machine run as “_application_name client”. You will see both machine are connected and start communicating within your local network.

    On Internet, it would be hard to get your IP/PORT working due to lots of secure channels and pretty much you will not get what you want.

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

Sidebar

Related Questions

I'm a newbie to scala. I'm trying an example from the book Programming Scala.
I am trying to work out an example from ".NET Domain Driven Design with
I'm trying to extract snippets of dialogue from a book text. For example, if
I'm trying to learn programming by myself, I'm working from a book that has
I'm trying to compile a simple example from thrust graph. At the moment I
I'm trying to use a KVO example I got from an iPhone tutorial book,
I am trying to test the example of checked iterator from Stroustrup's C++ book.
I was trying out a ListActivity example from the net. I am having problem
Trying out the example usage of codebrew rails-backbone , everything works fine but the
Hi while trying out jni example in this link http://wendro.blogspot.com/2010/03/jni-example-eclipse-dev-cpp.html?showComment=1309930446765#c5048550711511727724 with eclipse Helios windows

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.