mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Fix Connection broadcaster
This commit is contained in:
@@ -161,22 +161,15 @@ void Connection::ask()
|
|||||||
p << Connection::manager().connections_[0].port_handshake;
|
p << Connection::manager().connections_[0].port_handshake;
|
||||||
p << osc::EndMessage;
|
p << osc::EndMessage;
|
||||||
|
|
||||||
// broadcast on several ports, except myself
|
|
||||||
std::vector<int> handshake_ports;
|
|
||||||
for(int i=HANDSHAKE_PORT; i<HANDSHAKE_PORT+MAX_HANDSHAKE; i++) {
|
|
||||||
if (i != Connection::manager().connections_[0].port_handshake)
|
|
||||||
handshake_ports.push_back(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop infinitely
|
// loop infinitely
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
// broadcast the PING message on every possible ports
|
// broadcast on several ports
|
||||||
for(auto it=handshake_ports.begin(); it!=handshake_ports.end(); it++) {
|
for(int i=HANDSHAKE_PORT; i<HANDSHAKE_PORT+MAX_HANDSHAKE; i++) {
|
||||||
IpEndpointName host( "255.255.255.255", (*it) );
|
UdpSocket socket;
|
||||||
UdpTransmitSocket socket( host );
|
|
||||||
socket.SetEnableBroadcast(true);
|
socket.SetEnableBroadcast(true);
|
||||||
socket.Send( p.Data(), p.Size() );
|
socket.SendTo( IpEndpointName( "255.255.255.255", i ), p.Data(), p.Size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait a bit
|
// wait a bit
|
||||||
@@ -223,22 +216,27 @@ void ConnectionRequestListener::ProcessMessage( const osc::ReceivedMessage& m,
|
|||||||
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
|
||||||
int remote_port = (arg++)->AsInt32();
|
int remote_port = (arg++)->AsInt32();
|
||||||
|
|
||||||
// build message
|
// ignore requests from myself
|
||||||
char buffer[IP_MTU_SIZE];
|
if ( !NetworkToolkit::is_host_ip(remote_ip)
|
||||||
osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
|
|| Connection::manager().connections_[0].port_handshake != remote_port) {
|
||||||
p.Clear();
|
|
||||||
p << osc::BeginMessage( OSC_PREFIX OSC_PONG );
|
|
||||||
p << Connection::manager().connections_[0].name.c_str();
|
|
||||||
p << Connection::manager().connections_[0].port_handshake;
|
|
||||||
p << Connection::manager().connections_[0].port_stream_request;
|
|
||||||
p << Connection::manager().connections_[0].port_osc;
|
|
||||||
p << osc::EndMessage;
|
|
||||||
|
|
||||||
// send OSC message to port indicated by remote
|
// build message
|
||||||
IpEndpointName host( remote_ip.c_str(), remote_port );
|
char buffer[IP_MTU_SIZE];
|
||||||
UdpTransmitSocket socket( host );
|
osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
|
||||||
socket.Send( p.Data(), p.Size() );
|
p.Clear();
|
||||||
|
p << osc::BeginMessage( OSC_PREFIX OSC_PONG );
|
||||||
|
p << Connection::manager().connections_[0].name.c_str();
|
||||||
|
p << Connection::manager().connections_[0].port_handshake;
|
||||||
|
p << Connection::manager().connections_[0].port_stream_request;
|
||||||
|
p << Connection::manager().connections_[0].port_osc;
|
||||||
|
p << osc::EndMessage;
|
||||||
|
|
||||||
|
// send OSC message to port indicated by remote
|
||||||
|
IpEndpointName host( remote_ip.c_str(), remote_port );
|
||||||
|
UdpTransmitSocket socket( host );
|
||||||
|
socket.Send( p.Data(), p.Size() );
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// pong response: add info
|
// pong response: add info
|
||||||
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_PONG) == 0 ){
|
else if( std::strcmp( m.AddressPattern(), OSC_PREFIX OSC_PONG) == 0 ){
|
||||||
|
|||||||
@@ -83,8 +83,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string hostname_;
|
|
||||||
|
|
||||||
static void ask();
|
static void ask();
|
||||||
static void listen();
|
static void listen();
|
||||||
ConnectionRequestListener listener_;
|
ConnectionRequestListener listener_;
|
||||||
|
|||||||
Reference in New Issue
Block a user