void TcpRadio::connectToPeer()
{
if (_mode == SERVER)
return;
_peerNode.setConnection(TcpConnection::openOutcomingConnection(_peerNode.address(), _peerNode.port(), _creator, _timeout));
const TcpConnection * conn = _peerNode.getConnection();
connect(conn,
SIGNAL(status
(QString)),
this,
SIGNAL(updateStatus
(QString)));
connect(conn,
SIGNAL(status
(QString)),
this,
SLOT(writeLog
(QString)));
connect(conn, SIGNAL(readyRead()), this, SLOT(receive()));
emit updateStatus("Opening connection with peer: " + _peerNode.address());
}
TcpConnection* TcpConnection::openOutcomingConnection(const QString& serverName, int port, RadioMessageInterfaceCreatorFunction messageCreator, int timeout)
{
socket
->connectToHost
(serverName, port,
QIODevice::ReadWrite);
return new TcpConnection(socket, messageCreator, timeout);
}
void TcpRadio::connectToPeer()
{
if (_mode == SERVER)
return;
_peerNode.setConnection(TcpConnection::openOutcomingConnection(_peerNode.address(), _peerNode.port(), _creator, _timeout));
const TcpConnection * conn = _peerNode.getConnection();
connect(conn, SIGNAL(status(QString)), this, SIGNAL(updateStatus(QString)));
connect(conn, SIGNAL(status(QString)), this, SLOT(writeLog(QString)));
connect(conn, SIGNAL(readyRead()), this, SLOT(receive()));
emit updateStatus("Opening connection with peer: " + _peerNode.address());
}
TcpConnection* TcpConnection::openOutcomingConnection(const QString& serverName, int port, RadioMessageInterfaceCreatorFunction messageCreator, int timeout)
{
QTcpSocket* socket = new QTcpSocket();
socket->connectToHost(serverName, port, QIODevice::ReadWrite);
return new TcpConnection(socket, messageCreator, timeout);
}
To copy to clipboard, switch view to plain text mode
Bookmarks