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")