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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:05:09+00:00 2026-06-16T00:05:09+00:00

I have the following scripts: import socket import sys import traceback msg = socket.gethostbyname(socket.gethostname())

  • 0

I have the following scripts:

import socket
import sys
import traceback
msg = socket.gethostbyname(socket.gethostname())
dest = ('<broadcast>',10100)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, dest)
print "Sent."
while 1:
    (buf,address)=s.recvfrom(10100)
    if not len(buf):
        break
    print "Received from %s: %s" %(address, buf)

And then:

import socket
import traceback
import os
host = ''
port = 10100
sx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sx.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sx.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sx.bind((host,port))
while 1:
    try:
        message, address = sx.recvfrom(10104)
        print "Got data from", address
        sx.sendto("ola",address)
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        traceback.print_exc()

I’m having some trouble having both of them on the same script.
I just wanted to learn more about sockets, etc, this is nothing in particular.
My idea was to have just one script in each machine (Raspberry Pi), and whenever they’re on the same network, one will know about the presence of the other.
Hope I had explained right.

  • 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-16T00:05:10+00:00Added an answer on June 16, 2026 at 12:05 am

    Thanks for all the help.
    I’ve found these two links.
    The first one is really great, simple and is working like needed. May help someone else:
    http://www.cs.bilgi.edu.tr/~mgencer/Ders%20Malzemeleri/IThingTaggedFile/p2p.py

    https://github.com/zetaron/python-udp-p2p

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

Sidebar

Related Questions

I have a script that does something like the following... import socket hostIP=sys.argv[1] if
I have the following script: import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 127.0.0.1, 9050) socket.socket =
I have the following simple Python script: import socket import ssl if __name__ ==
I have the following script for sending mails using python import smtplib from email.mime.multipart
I have the following code: <fx:Script> <![CDATA[ import shared.GlobalsManager; import app.Globals; protected var globals:Globals=GlobalsManager.getGlobals();
I have the following two php scripts remove_directory.php <?php start_session(); $userId = $_SESSION['userId']; exec(escapeshellcmd(rm
I have the following rewrite set up: RewriteRule r/(.*) scripts/report.php?cp=1&id=$1 It works great to
I have the following scenario in my TFS: MyTeamProject Trunc Sources Scripts Installations Prod
I'm a newbie in bash scripts and have the following problem : I'm trying
I have HTML which includes scripts in following order <script src=../static/js/jquery.js type=text/javascript> <script src=../static/js/bootstrap.js

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.