In all the documentations of X11 that I've found so far something like this is written
Communication between server and clients is done by exchanging packets over a channel. The connection is established by the client (how the client is started is not specified in the protocol). (from wikipedia)
I haven't been able to find what is this channel exactly? A network channel for example? Is it on a port? Is it a memory map? Any help is appreciated.
The phrasing of 'channel' is intentionally vague as it can be either over a local socket, a remote connection (such as SSH), a named pipe, or another method that allows client/server bidirectional communication. Which is to say, a 'channel' is simply a connection between two points that facilitates exchange of data.
When perform X11 forwarding over SSH, the channel is the SSH connection. See the SSH man page for example:
$ man ssh
X11 connections and arbitrary TCP/IP ports can also be forwarded over the secure channel.
or per the x.org documentation:
The communications channel between an X client and server is full-duplex: either side can send a message to the other at any time. This is canonically implemented over a TCP/IP socket interface, though other communications channels are often used, including Unix domain sockets, named pipes and shared memory. The channel must provide a reliable, ordered byte stream---the X protocol provides no mechanism for reordering or resending packets.
X11 support multiple forms of communication between client and server. These so called channels can be TCP sockets, UNIX sockets, and a bunch of other network mechanisms, such as DECnet, token ring etc. TCP and UNIX sockets are really the only ones used today.
The X server is a process that has access to the graphics hardware, keyboard, and mouse. Any application that produces graphics on the computer screen is called a client. Usually, a workstation has on X server running, and multiple X clients. The applications (clients) need to connect to the X-Server via a TCP socket (identified by IP address and port number) or via a UNIX socket (identified by a file name, e.g. /tmp/X0)
If both, server and clients, run on the same system they usually connect through the UNIX socket. However, one of great features of X11 is that server and clients do not have the reside on the same system, but rather connect through the network via TCP sockets. This allows us to run applications on different computers on the network, and bring their graphics output on a single screen. (A single application may also connect to multiple X server and distribute graphics content on multiple screens.)
Related
I'm trying to understand if ZeroMQ can connect pub or sub socket to non existing (yet) ip address. Will it automatically connect when this IP address will appear in the future?
Or should I check up existance first before connecting?
Is the behavior same for PUB and SUB sockets?
The answer is buried somewhat in the manual, here:
for most transports and socket types the connection is not performed immediately but as needed by ØMQ. Thus a successful call to zmq_connect() does not mean that the connection was or could actually be established. Because of this, for most transports and socket types the order in which a server socket is bound and a client socket is connected to it does not matter. The ZMQ_PAIR sockets are an exception, as they do not automatically reconnect to endpoints.
As that quote says, the order of binding and connecting does not matter. This is extremely useful, as you don't then have to worry about start-up order; the client will be quite happy waiting for a server to come online, able to run other things without blocking on the connect.
Other Things That Are Useful
The direction of bind/connect is independent of the pattern used on top; thus a PUB socket can be connected to a SUB socket that has been bound to an interface (whereas the other way round might feel more natural).
The other thing that I think a lot of people don't realise is that you can bind (or connect) sockets more than once, to different transports. So a PUB socket can quite happily send to SUB clients that are both local in-process threads, other processes on the same machine via ipc, and to clients on remote machines via tcp.
There are other things that you can do. If you use the ZMQ_FD option from here, you can get ZMQ_EVENT notifcations in some way or other (I can't remember the detail) which will tell you when the underlying connection has been successfully made. Using the file descriptor allows you to include that in a zmq_poll() (or some other reactor like epoll() or select()). You can also exploit the heartbeat functionality that a socket can have, which will tell you if the connection dies for some reason or other (e.g. crashed process at the other end, or network cable fallen out). Use of a reactor like zmq_poll(), epoll() or select() means that you can have a pure actor model event-driven system, with no need to routinely check up on status flags, etc.
Using these facilities in ZMQ allows for the making of very robust distributed applications/system that know when various bits of themselves have died, come back to life, taken a network-out holiday, etc. For example, just knowing that a link is dead perhaps means that a node in your distributed app changes its behaviour somehow to adapt to that.
I'm building a strategy game, where players can battle each other. As for now, I'm focusing on making 1v1 PvP battles, but I also want to build an architecture, that will allow for further extension by up to 3v3 battles.
The game I create is based on socket Client/Server architecture. Every player, that will enter the game and press the "Find match" button, will be placed in a separate battle against one of the other players.
However, I have so many questions about how to structure the sockets:
Do I need a separate socket ("room socket") for each simultaneous battle?
Who should create and bind the room socket? If it's a client, how the server can connect to this socket if the client's ports are closed? If it's a server, see p. 3
Is it possible to bind all of these sockets to one port? How the client can connect to "his" socket if the addresses and the ports are the same?
When and how to open "room sockets" so that each client will get a corresponding endpoint? How to write it on server-side?
How many sockets do I need for matchmaking queue ("welcome sockets")?
Am I to use multithreaded programming, or it is possible to go without it?
I will be grateful for any help with it
P. S. Since the language I'm writing my server on isn't too prevalent, I can't use any ready solutions
From your question I suspect you could benefit from reviewing the Beej Guide to Network Programming.
Do I need a separate socket ("room socket") for each simultaneous battle?
I'm not sure what you mean by a "room" socket. If you mean that a different listening socket will be assigned per game, than that wouldn't be practical.
The normal way to go about is to have the server listen on a single socket (address / port) and each client will connect to the server's socket.
This means that the server will have a socket per active client + a listening socket and each client implementation will have a single socket (the connecting socket).
For a 1:1 game, the sockets can be "matched" to a couplet by the server, making that "couplet" into a room.
For a 1:many game you might consider using a pub/sub pattern by implementing "channels" and "subscriptions"... However, since (I'm assuming) a player can only enter a single game at a time, you might consider making an array or linked list of players per game.
Is it possible to bind all of these sockets to one port? How the client can connect to "his" socket if the addresses and the ports are the same?
Yes, it's possible and this is how servers actually work.
A listening socket behaves slightly different than a connection socket, in the sense that a listening socket can "accept" connections and create a new socket per connection.
When and how to open "room sockets" so that each client will get a corresponding endpoint? How to write it on server-side?
This is language dependent. Most languages have some kind of variation on the functions listen in the Beej Guide to Network Programming.
Generally a server will call listen and than create new client sockets using accept. A client will call connect and have a single socket.
How many sockets do I need for matchmaking queue ("welcome sockets")?
For a 1:1 game you will need a single socket "queued" as it waits for the next available connection.
Of course, this might be more complex. If a client has a game requirement (i.e., only players level 10 and up), you might require an ordered list or another data-store to manage the queue.
Am I to use multithreaded programming, or it is possible to go without it?
You can probably run thousands of games on a single machine with a single thread if you use an evented (non-blocking) design.
This really depends on how much work is performed on the server vs. how much work is performed on the client's computer.
Is it possible on Windows 7 to write a C++ or .NET program that finds out whether an existing, connected TCP socket created by another program has any data in its send or receive buffer?
Use case: There's a 16-bit legacy application doing TCP communication with some .NET applications. To work around a concurrency issue in the legacy app, it would be helpful if we could inspect either of two sockets that are connected to each other and tell whether there's some data sent on one end but not yet received on the other end.
The connection is TCP and the sockets are on the loopback interface (127.0.0.1).
Approach: WSADuplicateSocket() + WSAPoll() could be the solution but I don't know how to get a hold of the socket handle programmatically because the socket is created by another program.
I am new to Websockets. While reading about websockets, I am not been able to find answers to some of my doubts. I would like if someone clarifies it.
Does websocket only broadcasts the data to all clients connected instead of sending to a particular client? Whatever example (mainly chat apps) I tried they sends data to all the clients. Is it possible to alter this?
How it works on clients located on NAT (behind router).
Since client server connection will always remain open, how will it affect server performance for large number of connections?
Since I want all my clients to get real time updates, it is required to connect all my clients to server, so how should I handele the client connection limit?
NOTE:- My client is not a Web browser but a desktop application.
No, websocket is not only for broadcasting. You send messages to specific clients, when you broadcast you just send the same message to all connected clients, but you can send different messages to different clients, for example a game session.
The clients connect to the server and initialise the connections, so NAT is not a problem.
It's good to use a scalable server, e.g. an event driven server (e.g. Node.js) that doesn't use a seperate thread for each connection, or an erlang server with lightweight processes (a good choice for a game server).
This should not be a problem if you use a good server OS (e.g. Linux), but may be a limitation if your server uses a desktop version of Windows (e.g. may be limited to 200 connections).
With regards to the problem Bart is having in NAT router blocking JMS messages
I am trying to find the port number that clients receive openJMS messages on. After searching for ages on the web I can only find information about the server ports, nothing on the client. This is for a tcp connection.
If anyone can point me in the right direction I would be very grateful.
Thanks!
In general, the client port number will be different for each new connection. I could find no evidence that OpenJMS clients use specific port numbers when communicating with servers. Here are a few explanations.
Port Numbers
When a client process first contacts a server process, it may use a
well-known port number to initiate communication. Well-known port
numbers are assigned to particular services throughout the Internet,
by IANA, the Internet Assigned Numbers Authority. The well-known port
numbers are in the range 0 through 1023.
Well-known ports are used only to establish communication between
client and server processes. When this has been done, the server
allocates an ephemeral port number for subsequent use. Ephemeral port
numbers are unique port numbers which are assigned dynamically when
processes start communicating. They are released when communication is
complete.
TCP/IP Client (Ephemeral) Ports and Client/Server Application Port Use
In contrast, servers respond to clients; they do not initiate contact
with them. Thus, the client doesn't need to use a reserved port
number. In fact, this is really an understatement: a server shouldn't
use a well-known or registered port number to send responses back to
clients. The reason is that it is possible for a particular device to
have both client and server software of the same protocol running on
the same machine. If a server received an HTTP request on port 80 of
its machine and sent the reply back to port 80 on the client machine,
it would be sending the reply to the client machine's HTTP server
process (if present) and not the client process that sent the initial
request.
To know where to send the reply, the server must know the port number
the client is using. This is supplied by the client as the Source Port
in the request, and then used by the server as the destination port to
send the reply. Client processes don't use well-known or registered
ports. Instead, each client process is assigned a temporary port
number for its use. This is commonly called an ephemeral port number.
Similar answer on another question: How to decide on port number between client and server communication on internet:
Also, a client can connect to many servers on the same port. When the
clients connect, they will use a random port on there end.
Only the server needs to worry about using a free port, and the
clients need to know what this port is else they will not be able to
connect to your server.
Other possible help:
How to find number of ephemeral ports in use?