View Single Post
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#15
Originally Posted by xes View Post
i have found some interesting example for the Roku player:

https://gist.github.com/onaclov2000/4749011
http://www.remotecentral.com/cgi-bin...hread.cgi?4900
Yeah, that is the pretty much what I'm doing now, but in C++:

Code:
Socket::Socket(QObject *parent) :
    QObject(parent),
    m_retries(0)
{
    this->setObjectName("socket");
    this->connect(&m_socket, SIGNAL(connected()), this, SLOT(onConnected()));
    this->connect(&m_socket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
    this->connect(&m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    this->connect(&m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(onStateChanged(QAbstractSocket::SocketState)));
    this->connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
}

Socket::~Socket() {}

void Socket::getIPAddress() {
    QByteArray data = "M-SEARCH * HTTP/1.1\r\n" \
            "HOST: 239.255.255.250\r\n" \
            "MAN: ssdp:discover\r\n" \
            "MX: 4\r\n" \
            "ST: urn:schemas-upnp-org:device:MediaRenderer:1\r\n\r\n";

    QHostAddress address("239.255.255.250");

    qDebug() << "Binding: " << m_socket.bind(address, 1900);
    qDebug() << "Bytes sent:" << m_socket.writeDatagram(data, address, 1900);
}

void Socket::onConnected() {
    qDebug() << "Connected";
}

void Socket::onDisconnected() {
    qDebug() << "Disconnected";
}

void Socket::onReadyRead() {
    qDebug() << m_socket.readAll();
}

void Socket::onStateChanged(QAbstractSocket::SocketState state) {
    qDebug() << state;
}

void Socket::onError(QAbstractSocket::SocketError error) {
    qDebug() << error;
    qDebug() << m_socket.errorString();
}
So this should work, once I clean up the code.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following User Says Thank You to marxian For This Useful Post: