Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Posts: 6
Registered: ‎12-01-2009
My Device: Z10 Limited Edition
My Carrier: T-Mobile
Accepted Solution

QUdpSocket not binding to port 1900

I'm working on a program that needs to listen on port udp 1900 for multicast boradcast and discovery of a component in a network( SSDP Enables discovery of UPnP devices).  The code is already done and works perfectly on my BB10Dev Alpha, but when I try to run it on the BB Z10 Limited Edition I get the error (The bound address is already in use ). 

 

BB10 Alpha OS Version 10.9.10.35

BB Z10 OS Version 10.0.9.2372

 

Is this port no longer available for production OS? or is a problem with the OS Version of my Z10?  I haven't been able to upgrade my Z10 to a newest OS.

 

any suggestion?

Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: QUdpSocket not binding to port 1900

If you are discovering network devices, that implies you are sending multicast packets on port 1900. You don't have to listen on the same port - bind to 1901 instead (or any other port), and network devices will respond to whatever port you are bound to.
New Contributor
Posts: 6
Registered: ‎12-01-2009
My Device: Z10 Limited Edition
My Carrier: T-Mobile

Re: QUdpSocket not binding to port 1900

Find out that the problem is with OS 10.0.9 after I test it on others devices with OS 10.0.10.X it works as expected.

New Contributor
Posts: 6
Registered: ‎12-01-2009
My Device: Z10 Limited Edition
My Carrier: T-Mobile

Re: QUdpSocket not binding to port 1900

Problem persist on other devices with OS 10.0.10.X, apparently there is an app that "kidnap" the port an never release it.

New Contributor
Posts: 6
Registered: ‎12-01-2009
My Device: Z10 Limited Edition
My Carrier: T-Mobile

Re: QUdpSocket not binding to port 1900

Problem found, the blackberry MediaSharing Services bind to 1900 and do not share the port.  To bind to the port you need to turn off the MediaSharing Services on Settings and it works right away.

Developer
Posts: 169
Registered: ‎03-25-2011
My Device: Playbook, Z10 L.E.
My Carrier: Vodafone NL

Re: QUdpSocket not binding to port 1900

Hi cgonzalezd,

 

I'm doing an app which also needs to discover a SSDP Enabled device on a network via broadcast but I cannot get it to work. I'm a noob in Qt, Cascades and also networking. Could you help me figureout what I'm doing wrong?

void SSDPSearcher::startSearch()
{
	// Create the UDP socket object.
	m_udpSocket = new QUdpSocket(this);

	// Assemble the content of the datagram
	QString params =
			QString("M-SEARCH * HTTP/1.1\nHOST: %1:%2\nMAN: ssdp:discover\nMX: 10\nST: ssdp:all")
			.arg(m_groupAddress.toString()) // QHostAddress("239.255.255.250")
			.arg(m_port); // 1900
	QByteArray datagram;
	datagram.append(params);

	// Connect the readyRead() signal which means we found something
	connect( m_udpSocket, SIGNAL( readyRead() ), this, SLOT( readPendingDatagrams() ));

	// bind the socket so we can receive replies from the discovery services
	m_udpSocket->bind(m_groupAddress, m_port);

	// Send the multicast datagram with the given content to port 1900
	m_udpSocket->writeDatagram(datagram.data(), datagram.size(), m_groupAddress, m_port);

	// If nothing is found in 1s, quit and let the user enter the IP manually.
	QTimer::singleShot(m_timeOut, this, SLOT(timedOut()));
}

void SSDPSearcher::readPendingDatagrams()
{
	while( m_udpSocket->hasPendingDatagrams() ) {
		QByteArray datagram;
		datagram.resize( m_udpSocket->pendingDatagramSize());
		QHostAddress sender;
		quint16 senderPort;

		m_udpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);

		if(datagram.size() > 0){
			QVariantMap result;
			QVariant variant;

			// send the data as JSON-like structure
			result["senderAddress"] = sender.toString();
			result["senderPort"] = senderPort;
			result["data"] = datagram;

			variant = static_cast<QVariant>(result);

			// emit the signal with the data from the received datagram
			emit resultReceived( variant );
		}
	}
}

I saw some other solutions (Brisa Qt) but they were using 3rd party C/C++ libraries. Is it possible to achieve this just using Qt libs?

 

On your last post, you found a workaround for the port problem. Did you create a Bug Report or something so BlackBerry is aware of this conflict?

It would be really nice if they created a small library for SSDP functionality that doesn't conflict with other apps and services. 

 

Thanks in advance for the help.

Cheers!

Cheers!
Developer
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

Re: QUdpSocket not binding to port 1900

The Multicast receiver and Multicast sender sample apps are a good starting point

 

http://blackberry.github.com/Qt2Cascades-Samples/docs/multicastreceiver.html

 

http://blackberry.github.com/Qt2Cascades-Samples/docs/multicastsender.html

 

A few tips:

 

1. Don't bind to 1900 (you don't need to) - use 1901 instead which AFAIK is what regular SSDP does. Yes you send on 1900, but receive on something different. 

 

2. Bind with QUdpSocket:Smiley FrustratedhareAddress

 

3. SSDP requires UDP multicast - you must therefore use the QUdpSocket::joinMulticastGroup function

 

4. set the SSDP TTL with setSocketOption(QAbstractSocket::MulticastTtlOption, <your value here>);

 

5. Run WireShark as your main debugging tool. You can inspect the exact packet that gets sent over the network, and ensure that the right data is being sent/received

 

Thats it..

 

 

New Contributor
Posts: 6
Registered: ‎12-01-2009
My Device: Z10 Limited Edition
My Carrier: T-Mobile

Re: QUdpSocket not binding to port 1900

Those sample apps contains all the info you needed, is exactly the code I used as base for my app.  

 

In my case binding to a different port than 1900 didn't work with the specific device I was trying to discover, other devices on the network did response to the request, but for my specific case looks like the device only reply to port 1900.  So that's why I was on the need to bind to it.  

 

I agree that binding to another port should work for most of the cases.

 

best,

 

 

Highlighted
Developer
Posts: 169
Registered: ‎03-25-2011
My Device: Playbook, Z10 L.E.
My Carrier: Vodafone NL

Re: QUdpSocket not binding to port 1900

[ Edited ]

Hi guys,

 

I have checked the MulticastReceiver and Sender apps but they are bit different from what I need since they are designed to work together. They know how to find each other easily.

 

In my case, I want to discover all UPnP Enabled devices on my network using SSDP. The Multicast apps are not designed to work like this ... correct ? Maybe it is and I don't understand how ...

 

This is the description that I'm trying to implement using just Cascades. I hope this will clear any doubts of what I'm trying to achieve. Please let me know if you find any mistakes on my implementation or more tips:

 

Discovery

When a UPnP capable device joins a network and wants to know what UPnP services are available on the network, it sends out a discovery message to the multicast address 239.255.255.250 on port 1900 via the UDP protocol. This message contains a header, similar to a HTTP request. This protocol is sometimes referred to as HTTPU (HTTP over UDP):

M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: ssdp:discover
MX: 10
ST: ssdp:all

 

All other UPnP devices or programs are required to respond to this message by sending a similar message back to the device, using a UDP unicast, announcing which UPnP profiles the device or program implements. An interesting quirk: it is sent back with UDP unicast to the port the device discovery message was sent from. For every profile it implements one message is sent:

HTTP/1.1 200 OK
CACHE-CONTROL:max-age=1800
EXT:
LOCATION:http://10.0.0.138:80/IGD.xml
SERVER:SpeedTouch 510 4.0.0.9.0 UPnP/1.0 (DG233B00011961)
ST:urn:schemas-upnp-org:service:WANPPPConnection:1
USN:uuid:UPnP-SpeedTouch510::urn:schemas-upnp-org:service:WANPPPConnection:1

 

The above is a slightly edited response that is sent by an Alcatel/Thomson Speedtouch ADSL modem, which implements the WANPPPConnectionprofile.

At a regular interval UPnP capable devices or programs have to send a message to announce their services. A notification message is more or less the same as a response message to a discovery, but are sent to the UPnP multicast address 239.255.255.250 on port 1900 via UDP and have the ST header replaced by a similar header called NT.

 

Original from: http://www.upnp-hacks.org/upnp.html

Cheers!