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

melvimbe
February 26, 2021

I think we are talking about two different things here.   What Bruce ( @Airgetlam ) is refering to is how a speaker retrieves the audio stream it’s been instructed to play.  Streaming services is obvious, as the speakers know the address to go retrieve the stream.  He’s expanding the discussion to explain that ‘play audio from this device’ isn’t really different.  The speaker is on the same network as the phone/tablet controlling device and therefore knows where to access the music files on your phone/tablet.

I don’t think that was the original question though.  It’s not about how the speaker retrieves an audio stream, but how a device that is not currently connected to your home network can control Sonos speakers (really any IOT device) inside your network when dynamic IP address assignments are used.  This really a more generic question as this is a function of most IOT devices.  How do you control your lights, your alarms, your cameras, etc when outside of the network?

It’s my understanding that Sonos, like any other company that sells IOT devices, maintains a server that receives control commands from your phone/tablet,etc or other services (Amazon Alexa) and is then responsible for sending the command on to the appropriate device inside your home network.  In this way, your phones/tablets and other services don’t need to individually track the IP address of your IOT devices, they only contact the cloud server that tracks that information.

That still doesn’t answer how a Sonos cloud, or any other IOT related cloud, is able to know the internal dynamic IP address of the devices in your home network.  I am not exactly sure, though I suspect that your devices will periodically ping the service with it’s current IP settings.  Someone more versed in networks would need to answer.  I did try and do some google research on it, but too many companies trying to sell IOT and cloud computing to sift through.

Danny
controlav
Lead Maestro
February 26, 2021

@Airgetlam is mostly correct in his description.

However there is a Sonos Cloud. It is used for voice control integration and things like Spotify Direct, where music services can directly control what the devices in your home play (though only a few of the ~70 supported services do this). It is also used for a few admin-level Settings, such as line-in level and explicit track permissions, as well as storage for diagnostic data.

For details on how a music service can send music directly to a speaker in your home, skipping your controller, read https://developer.sonos.com/build/direct-control/ - the music services connects to the Sonos cloud with the credentials you entered via the Sonos login page in their app. The Sonos devices in your home “phone home” regularly and pick up any commands generated in the Sonos cloud for playback.

The Sonos Cloud is not necessary for local control of Sonos players, or to play music from a streaming service (which uses SMAPI, not the cloud API). Third party apps such as mine have no need for its features, and compared to the “local” APIs we use the cloud API is seriously deficient for use by a controller app: I know this because I created a prototype that did just that.

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
melvimbe
February 26, 2021

The Sonos devices in your home “phone home” regularly and pick up any commands generated in the Sonos cloud for playback.

 

How often is regularly?  If the cloud can’t initiate contact with the speakers, then the speakers would need to check with the cloud at a high frequency, correct?  Something around once a second or less?

Danny
controlav
Lead Maestro
February 26, 2021

The Sonos devices in your home “phone home” regularly and pick up any commands generated in the Sonos cloud for playback.

 

How often is regularly?  If the cloud can’t initiate contact with the speakers, then the speakers would need to check with the cloud at a high frequency, correct?  Something around once a second or less?


I don’t know, but if I did it I would use a long-running http request or SignalR, which has minimal overhead and isn’t really timer-based as my wording implied.

Author of the leading independent Sonos apps for Android, MacOS, iOS, Windows and Xbox.
ReezaroAuthor
Contributor I
March 1, 2021

@Airgetlamis mostly correct in his description.

However there is a Sonos Cloud. It is used for voice control integration and things like Spotify Direct, where music services can directly control what the devices in your home play (though only a few of the ~70 supported services do this). It is also used for a few admin-level Settings, such as line-in level and explicit track permissions, as well as storage for diagnostic data.

For details on how a music service can send music directly to a speaker in your home, skipping your controller, read https://developer.sonos.com/build/direct-control/ - the music services connects to the Sonos cloud with the credentials you entered via the Sonos login page in their app. The Sonos devices in your home “phone home” regularly and pick up any commands generated in the Sonos cloud for playback.

The Sonos Cloud is not necessary for local control of Sonos players, or to play music from a streaming service (which uses SMAPI, not the cloud API). Third party apps such as mine have no need for its features, and compared to the “local” APIs we use the cloud API is seriously deficient for use by a controller app: I know this because I created a prototype that did just that.

 

Thanks @controlav for your reply and the link.

I am familiar with cloud and API request as I did some projects in python and flask.

The only thing that I could not figure it out is how Sonos servers/clouds can track the IP address of my Sonos speakers connected to my home WiFi with DHCP set up?

I do not think Sonos speakers continuously check the Sonos server for any commands as it increases the traffic and other issues.

James L.
Retired Community Staff
March 1, 2021

The only thing that I could not figure it out is how Sonos servers/clouds can track the IP address of my Sonos speakers connected to my home WiFi with DHCP set up?

I do not think Sonos speakers continuously check the Sonos server for any commands as it increases the traffic and other issues.

Hey @Reezaro,

 

The Sonos cloud server doesn’t know or need your local IP addresses. Each speaker establishes a connection to a cloud endpoint and performs pings at regular intervals (I’m not sure of the frequency though, sorry!) to keep the connection alive. Commands from the cloud use this connection to send instructions to your system for whatever task is being performed. 

Your DHCP assigned local IP is only used by the speakers themselves and other devices connected to your local network, not by music services or cloud servers.

 
 
 
 
 
Mark good posts by pressing the like button, and select the best answer on questions you've asked to help others find solutions.
ReezaroAuthor
Contributor I
March 3, 2021

The only thing that I could not figure it out is how Sonos servers/clouds can track the IP address of my Sonos speakers connected to my home WiFi with DHCP set up?

I do not think Sonos speakers continuously check the Sonos server for any commands as it increases the traffic and other issues.

Hey @Reezaro,

 

The Sonos cloud server doesn’t know or need your local IP addresses. Each speaker establishes a connection to a cloud endpoint and performs pings at regular intervals (I’m not sure of the frequency though, sorry!) to keep the connection alive. Commands from the cloud use this connection to send instructions to your system for whatever task is being performed. 

Your DHCP assigned local IP is only used by the speakers themselves and other devices connected to your local network, not by music services or cloud servers.

 
 
Hey@James L. 
 
Thanks for your reply.
Tho I can understand the ping mechnism of each speakers, it is a little bit weird for me because it highly increases the data traffic on Sonos servers.
Also, I can’t underand how Sonos cloud sends command through that established conenction!!! I think the cloud needs a valid IP address to send commands back. Cloud you explain it a little bit more? 
RalpfocusAnswer
Prodigy III
March 3, 2021

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

ReezaroAuthor
Contributor I
March 3, 2021

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 but not your speaker. Your external ip address 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.

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.

 

So as I understood, Sonos cloud can just track the IP until my router. The rest, is my router's task to automatically transfer data to my speakers? 

Prodigy III
March 3, 2021

If you meant “ track the IP until my router changes its IP address” then yes ish. It is not really tracking there is an open connection rather like a telephone call and data can flow between both ends for as long as the connection is open. You are correct the router is responsible for transferring the data to the speaker.

If you look at my updated reply the Sonos cloud cannot initiate the connection. The speaker initiates the connection which it keeps open for a long time. I have no idea how long “long” is but whenever it reaches the end the speaker will just initiate a new connection.