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 561467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:27:10+00:00 2026-05-13T12:27:10+00:00

I would like to listen on 2 different UDP port with the same server.

  • 0

I would like to listen on 2 different UDP port with the same server.
I use SocketServer lib for my server, and basicly it looks like that;

SocketServer.UDPServer((”, 7878),CLASSNAME)

I would like to listen on 7878 and 7879 with the same server and same file.
Is that possible? If yes how?

  • 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-13T12:27:11+00:00Added an answer on May 13, 2026 at 12:27 pm

    Sure you can, using threads. Here’s a server:

    import SocketServer
    import threading
    
    
    class MyUDPHandler(SocketServer.BaseRequestHandler):
        def handle(self):
            data = self.request[0].strip()
            socket = self.request[1]
            print "%s wrote:" % self.client_address[0]
            print data
            socket.sendto(data.upper(), self.client_address)
    
    
    def serve_thread(host, port):
        server = SocketServer.UDPServer((host, port), MyUDPHandler)
        server.serve_forever()
    
    
    threading.Thread(target=serve_thread,args=('localhost', 9999)).start()
    threading.Thread(target=serve_thread,args=('localhost', 12345)).start()
    

    It creates a server to listen on 9999 and another to listen on 12345.
    Here’s a sample client you can use for testing this:

    import socket
    import sys
    
    HOST, PORT = "localhost", 12345
    data = 'da bomb'
    
    # SOCK_DGRAM is the socket type to use for UDP sockets
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    # As you can see, there is no connect() call; UDP has no connections.
    # Instead, data is directly sent to the recipient via sendto().
    sock.sendto(data + "\n", (HOST, PORT))
    received = sock.recv(1024)
    
    print "Sent:     %s" % data
    print "Received: %s" % received
    

    Note: this was taken from the docs of the SocketServer module, and modified with threads.

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

Sidebar

Related Questions

I would like to host 2 different domains in the same server using Nginx.
I would like to listen for the mouse over event in GWT 1.6. Since
I have a text area on which I would like to listen to change
Instead of having nested callbacks in JS, I would like to fire and listen
Would like a for loop in jquery so that: For every hover_link: show hidden
Would like to be able to set colors of headings and such, different font
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to know if there is a way that jquery or some
I have an ai loop that I would like to write for my iphone
Accuracy Vs. Precision What I would like to know is whether I should use

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.