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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:02:51+00:00 2026-06-11T20:02:51+00:00

With Python, is it possible to send UDP data on local host and some

  • 0

With Python, is it possible to send UDP data on local host and some port, then simultaneously inside same program, listen to different port on local host? I keep getting error 48’address already in use’ and have tried using python’s reuse address, although I’m pretty sure it won’t work for this application anyways.

Background: I don’t know anything about software development much less Python, this is just something that someone asked for at work.

I appreciate any help.

from threading import Thread
import time
import socket


HOST = 'localhost'
PORT = 5455
PORT1 = 5457
data1 = "1"

s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST,PORT1))


a = 0
def myfunction(string, *args):
    while 1:
        cmd = int( raw_input("send message: ") )
        if (cmd == 1):
            s.sendto(data1, (HOST,PORT))
            time.sleep(1)

def myfunction2(string, *args):
    while 1:
        print s.recv(30)
        time.sleep(.5)

if __name__=='__main__':

    try:
        Thread(target=myfunction, args=(a, 1)).start()
        Thread(target=myfunction2, args=(a, 1)).start()
    except Exception, errtxt:
        print errtxt
  • 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-11T20:02:52+00:00Added an answer on June 11, 2026 at 8:02 pm

    Yes, it is. In any language. You are probably listening twice to the same port; TCP and UDP endpoints are characterized by the IP address and the port. “Address already in use” will only appear for a full match, same address and same port.

    Also, verify that the listening port isn’t already in use with netstat.

    UPDATE (thanks to l4mpi): you will get an “access denied” if you try to use a port below 1024 without having superuser privileges.

    UPDATE

    I have slightly modified your code; one of the problems you had was some confusion about sending and receiving sockets, which was the “client” function and which was the “server”.

    I have taken the liberty of querying for a message body instead of “1”, but it is easy to put things back if necessary.

    from threading import Thread
    import time
    import socket
    
    CONN = ('localhost', 5455)
    
    def fn_client(string, *args):
        cs = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        while 1:
            cmd = int( raw_input("command (1 to send): ") )
            if (cmd == 1):
                data = raw_input("message to send: ")
                cs.sendto(data, CONN)
                time.sleep(1)
    
    def fn_server(string, *args):
        ss = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
        ss.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        ss.bind(CONN)
        while 1:
            print "Server received '%s'" % (ss.recv(30))
            time.sleep(.5)
    
    if __name__=='__main__':
    
        a = 0
        try:
            Thread(target=fn_client, args=(a, 1)).start()
            Thread(target=fn_server, args=(a, 1)).start()
        except Exception, errtxt:
            print errtxt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to send an array through UDP Sockets using Python? I am
Is it possible to send a status code other than 200 via a python
Possible Duplicate: How to send Email Attachments with python I would like to edit
I am currently doing some I/O intensive load-testing using python. All my program does
Possible Duplicate: Receive and send emails in python I've been looking into sending mail
Possible Duplicate: How to send an e-mail from a Python script that is being
We wrote a Delphi program that send some informations with CDO. In my Win7
Possible Duplicate: python: urllib2 how to send cookie with urlopen request If I have
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Python: What is the best way to check if a list is

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.