1

I have one server and other some client nodes in the ad-hoc network. Some nodes are in the range of server which can directly be received hello message and broadcast to neighbors but which nodes are not in the range of server that will receive hello message from neighbors nodes of the server.
I have the first problem in my program that I need to put host id at client side which will transfer message to client or client to client, for server to client I can use IP address by using socket (socket.socket(socket.AF_INET, socket.SOCK_STREAM)) but for next client which are not a neighbors of server for those nodes I need broadcast id because those nodes know only server IP So how i can programme for broadcasting the hello message by using broadcast address instead of IP address Here is code in client-side, I am putting my Host id but host id is only valid up to one hop from the server and the remaining node will not accept hello message because they will not connect with another node ip and also i want to get one hello message on each node. Plz help to modify my below code.

import socket

print ("----trying to connect with host")
HOST = ''
PORT = 5000              
HOST1='101.0.0.2'
PORT1=5001
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST,PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)

        while True:

            data = conn.recv(4096)
            print (data)
            if not data: break
            conn.sendall(data)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s1:
    try:
        s1.connect ((HOST1,PORT1))

        s1.sendall (b'hello i am client 1')

        print ("Connected to ", HOST1)
    except ConnectionRefusedError:
        print ("Connection Refused")
Long
  • 3
  • 3
  • Broadcast is not possible over SOCK_STREAM. See https://stackoverflow.com/questions/22878625 how to write broadcasting server and client – Zaboj Campula May 31 '18 at 07:46
  • @Zaboj Campula Thansk for answering – Long May 31 '18 at 10:47
  • My question is : How i can broadcast only "hello " message to all my neighbors without mentioned address like 255.255.255.255.in send () function? – Long May 31 '18 at 11:12
  • So do you want to send a separate "hello" to all of clients over existing TCP connenctions? – Zaboj Campula May 31 '18 at 13:40
  • Each node needs to receive 'hello' even if it is not in the range of server. The neighbor's node of the server will broadcast 'hello' message which they received from a server So, in this case, I need to broadcast "Hello" message using broadcast ID – Long May 31 '18 at 19:01
  • Still not sure what you want. Do you mean you have ad-hoc 802.11g network with more than 2 computers and there is no "each-to-each" visibility and you want nodes to forward message to nodes where is no radio signal from server? – Zaboj Campula Jun 01 '18 at 11:03

0 Answers0