When I request X forwarding from SSH server, then SSH server sets a $DISPLAY variable with value localhost:10.0. In addition, it starts to listen on 127.0.0.1 port 6010(and also ::1 port 6010 for IPv6):

Netid  State      Recv-Q Send-Q                                     Local Address:Port                                                      Peer Address:Port                
LISTEN     0      128                                               127.0.0.1:6010                                                                    *:*                     users:(("sshd",pid=11405,fd=10))

How do X clients know that they will need to connect to TCP port 6010? Does this work in a way that by default they connect to TCP port 6000+<display number> and as display number is in this example 10, then they will connect to TCP port 6010?

share|improve this question
    
A term that might be helpful is well-known port. – chrylis 2 hours ago

It’s part of the X11 protocol (search for "6000") and is documented e.g. in Xorg(1):

Xorg listens on port 6000+n, where n is the display number. This connection type can be disabled with the -nolisten option (see the Xserver(1) man page for details).

share|improve this answer

Yes.

Just as browsers know to connect to a webserver on port 80 (unless otherwise specified), X clients know to talk to X servers on port 6000 + display number (unless otherwise specified).

These expectations are what standards (and, more broadly, documentation) give us — else, interaction between computers would be extremely cumbersome.

share|improve this answer
    
I can make an educated guess whom your pointed comment is aimed at, but it could look like you are having a go at the questioner, which (if my guess is correct) is not the case at all. It is best to make that clear. – JdeBP 3 hours ago
    
@JdeBP: Eh? What "pointed comment"? Where am I "having a go" at anyone?? I'm very simply answering the question... – Lightness Races in Orbit 2 hours ago
    
Your pointed comment about standards, of course. – JdeBP 52 mins ago
    
@JdeBP: I think you must be misreading it, because I have absolutely no idea what you're talking about. That web browsers should talk to webservers on port 80 is given by as close to a standard as there is: the RFC(s) on HTTP. Similar "legislation" is passed for all other protocols. That's how networks are defined. Similarly, that's how X clients "know" which ports to use, which was the question posted above. What's "pointed" about that? – Lightness Races in Orbit 47 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.