Hi!
I try to connect to a host using broadcast and bind the connected port to receive a message.
With Qt3 QSocketDevice it worked fine doing this:
address.setAddress( "255.255.255.255" );
socket->setAddressReusable( true );
socket->connect( address, 8080 );
address.setAddress( "0.0.0.0" );
socket2->setBlocking( false );
socket2->setAddressReusable( true );
socket2->bind( address, socket->port() );
const char *msg = "my_message";
socket->writeBlock( msg, strlen(msg) );
address.setAddress( "255.255.255.255" );
socket->setAddressReusable( true );
socket->connect( address, 8080 );
address.setAddress( "0.0.0.0" );
socket2->setBlocking( false );
socket2->setAddressReusable( true );
socket2->bind( address, socket->port() );
const char *msg = "my_message";
socket->writeBlock( msg, strlen(msg) );
To copy to clipboard, switch view to plain text mode
I tried with QUdpSocket
address.setAddress( "255.255.255.255" );
socket->connectToHost( address, 8080 );
address.setAddress( "0.0.0.0" );
printf("bind: %i\n",socket2
->bind
( socket
->localPort
(),
QUdpSocket::ReuseAddressHint|QUdpSocket
::ShareAddress ));
printf("error %i: %s\n",socket2->error(),socket2->errorString().ascii());
const char *msg = "my_message";
socket->write( msg, strlen(msg) );
address.setAddress( "255.255.255.255" );
socket->connectToHost( address, 8080 );
address.setAddress( "0.0.0.0" );
printf("bind: %i\n",socket2->bind( socket->localPort(),QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress ));
printf("error %i: %s\n",socket2->error(),socket2->errorString().ascii());
const char *msg = "my_message";
socket->write( msg, strlen(msg) );
To copy to clipboard, switch view to plain text mode
I cannot bind the receiving socket.
I tried it on windows:
"error 3: The address is protected."
and on linux:
"error 8: The bound address is already in use"
Any ideas how to get this to work?
Bookmarks