Answer the question
In order to leave comments, you need to log in
How to correctly implement a search for a device on the network?
Good day.
In view of the fact that I am not familiar with administration in general and the network structure in particular, I try to solve the following question: how to implement a search for a device on the network?
More specifically, the situation is as follows: I am doing a small application on react and would like to simplify the search for devices within the same subnet. I imagine the process itself as follows, the server sends some kind of message (of the hello type) to the broadcast, when the client turns on the application, it starts listening and catching udp packets, thereby finding the server that broadcasts and then normal work enters the scheme, but I can’t do it, I give the code below:
a demo server that sends out:
from socket import *
import time
cs = socket(AF_INET, SOCK_DGRAM)
while(True):
cs.sendto(b'This is a test', ('0.0.0.0', 12345))
print('test')
time.sleep(1)
import DGRAM from 'dgram';
let udpSocket = DGRAM.createSocket('udp4');
udpSocket.bind(12345, '0.0.0.0');
udpSocket.on('message', (msg, info) => {
console.log(msg, info)
});
Answer the question
In order to leave comments, you need to log in
Actually, I solved the problem, in the end it was necessary to specify the server options when sending (SO_BROADCAST https://www.ibm.com/support/knowledgecenter/en/SSL... - description here)
the server code itself:
from socket import *
import time
cs = socket(AF_INET, SOCK_DGRAM)
cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
while(True):
cs.sendto("TestText".encode(), ('255.255.255.255', 12345))
print('test')
time.sleep(1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question