Skip to main content
Contributor I
February 25, 2021
Answered

How Sonos plays a music from my home speakers

  • February 25, 2021
  • 23 replies
  • 751 views

Hi,

I have 2 sonos one. Every thing works well but I am a technical question. I hope I posted in a right subsection.

I would like to know how sonos sends and plays a music which I send it from a different network like my mobile data. How it finds my home speaker IP and port?

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.
Best answer by Ralpfocus

When the sonos speaker communicates to the sonos cloud it opens a long running connection with the sonos cloud which will have very low impact as @controlav says. Once a connection is open between two devices they both know an ip address (endpoint) that enables data to flow between them. The endpoint at your end will normally  be the external ip adress of your router - this is assigned by your Internet provider.  When the sonos cloud “responds" on that connection it talks to the endpoint on your router. Your router keeps track of open connections and when a message arrives for your sonos device the router “knows" which device initiated the connection and forwards the message onto that device. 

Sonos therefore knows the ipaddress of your house, your external ip address which can change -  it is under the control of your provider.  Some never change some, less common, change quite regularly. If you use a vpn provider then the endpoint sonos sees is the vpn providers.

By default your home router prevents people from outside initiating connections so the Sonos cloud cannot initiate the connection, your sonos system initiates the connection probably at start up.

@James L. is right that the sonos cloud does not need your local address because it does not initiate the connection but once the connection is open it does know your routers address and despite what he says the message sent to the cloud  probably contains the ip address of the  speaker

As an aside the provider e.g. sonos can use the endpoint ip address to roughly get the physical location of your router. This is one of the ways that companies can target advertising.

Edited to make a correction about knowing local ip address

23 replies

106rallye
February 25, 2021

As far as I know connecting to Sonos from outside your networkl is only possible through Spotify Connect. If so, this isn't a Sonos question. Or do you mean something else?

Airgetlam
February 25, 2021

The Sonos system runs on a computer inside each speaker. Using the controller as a remote control, you tell that computer on the speakers where to reach out and get that data ftprom. For streaming sources, the software running on each speaker has predefined locations to reach out to a server to get the data from the streaming company. For playing data ‘on this mobile device’, the controller should send its current location to the software running on the speakers so that the speaker can connect to that device to get the data to play.

This is one reason you can only play ‘from this device’ and not ‘from that device’, since the address could change as it leaves and enters the network. And also why Sonos doesn’t allow playlists that contain music ‘on this device’, since a mobile device can leave the network. 

Bruce
melvimbe
February 25, 2021

As far as I know connecting to Sonos from outside your networkl is only possible through Spotify Connect. If so, this isn't a Sonos question. Or do you mean something else?

 

Actually, I believe Sonos implemented a cloud server when Alexa integration went live.  So generally, apps/services that can control your Sonos system from outside your home network will access the Sonos cloud server, which then gives the command to your Sonos speaker.  The speaker itself will then execute the command, usually to connect to a streaming service and play audio.  It’s not just Spotify, but Amazon, Pandora, and a few others as well.  And there are some IFTTT stuff you can do as well.

 

Danny
Airgetlam
February 25, 2021

That’s not my understanding. The cloud services are, to my knowledge, provided not by Sonos, but by Amazon and Google, for their respective voice systems. Sonos just points to whichever cloud service you’ve set up as a voice control, in exactly the same manner as a streaming music source.

At least, that’s the way I perceive it to work. Feel free to point at anything that suggests I’m incorrect. 

Bruce
melvimbe
February 25, 2021

That’s not my understanding. The cloud services are, to my knowledge, provided not by Sonos, but by Amazon and Google, for their respective voice systems. Sonos just points to whichever cloud service you’ve set up as a voice control, in exactly the same manner as a streaming music source.

At least, that’s the way I perceive it to work. Feel free to point at anything that suggests I’m incorrect. 

 

I don’t think Amazon and Google cloud services talk directly to the Sonos speakers. The commands are passed through a Sonos cloud first.  I remember having discussions with Ryan S about this back when Alexa control was released...but that was a long time ago and I could be mis-remembering.

Danny
ReezaroAuthor
Contributor I
February 26, 2021

As far as I know connecting to Sonos from outside your networkl is only possible through Spotify Connect. If so, this isn't a Sonos question. Or do you mean something else?

 

It works for all major music stream providers not only spotify. 

ReezaroAuthor
Contributor I
February 26, 2021

The Sonos system runs on a computer inside each speaker. Using the controller as a remote control, you tell that computer on the speakers where to reach out and get that data ftprom. For streaming sources, the software running on each speaker has predefined locations to reach out to a server to get the data from the streaming company. For playing data ‘on this mobile device’, the controller should send its current location to the software running on the speakers so that the speaker can connect to that device to get the data to play.

This is one reason you can only play ‘from this device’ and not ‘from that device’, since the address could change as it leaves and enters the network. And also why Sonos doesn’t allow playlists that contain music ‘on this device’, since a mobile device can leave the network. 

I do not get that. how can I play a music from my cellphone with mobile data on my sonos speaker conencted to my home wifi with dynamic IP? my cellphone would have many different IPs and networks. But I can always send musics to my sonos instantly and it plays. 

ReezaroAuthor
Contributor I
February 26, 2021

As far as I know connecting to Sonos from outside your networkl is only possible through Spotify Connect. If so, this isn't a Sonos question. Or do you mean something else?

 

Actually, I believe Sonos implemented a cloud server when Alexa integration went live.  So generally, apps/services that can control your Sonos system from outside your home network will access the Sonos cloud server, which then gives the command to your Sonos speaker.  The speaker itself will then execute the command, usually to connect to a streaming service and play audio.  It’s not just Spotify, but Amazon, Pandora, and a few others as well.  And there are some IFTTT stuff you can do as well.

 

it should be something like that but how sonos cloud knows my current speaker’s IP address as it is dynamic? 

ReezaroAuthor
Contributor I
February 26, 2021

That’s not my understanding. The cloud services are, to my knowledge, provided not by Sonos, but by Amazon and Google, for their respective voice systems. Sonos just points to whichever cloud service you’ve set up as a voice control, in exactly the same manner as a streaming music source.

At least, that’s the way I perceive it to work. Feel free to point at anything that suggests I’m incorrect. 

Tho I guess it first connects to sonos cloud, no matter to each one it connects first. the issue is how the cloud/server knows the current IP address of my speaker with dhcp setup? it might change many times per days. 

Airgetlam
February 26, 2021

There is no ‘Sonos Cloud’.

Your controller, when you start it and connect to your WiFi, gets an IP address from your router. When you play ‘from this device’, the controller communicates that IP address to the speakers, which then use it to get the data from your device. When you leave your WiFi, that IP address can and likely will change. Again, this is why you can’t add music from a mobile device in a playlist inside the Sonos controller. If that mobile device is ‘missing’ from the WiFi, how would another person be able to play that music?

It would be odd for the speakers to work differently for streaming from your device as opposed to streaming from an internet source such as Spotify or Apple Music. Significantly more coding effort. It makes more sense to use the existing process to do a similar thing. 

However, this is conjecture on my part. Folks like @controlav would have better knowledge, he has written his own controllers for Sonos, and is likely much more familiar with the way the internal system works than I. 

Bruce