My client program consists of three threads and six sockets
Ouch!
The second thread has one listening TCP socket, constantly listening for new connections since I'm using a selector, and one socket handling incoming messages through the selector. The third thread works almost exactly in the same way as the second, although with UDP sockets rather than TCP.
Why do you still listen for connections at your client? A connection works this way:
Server listens on a port, using a socket. Take it as the "door to the outside world".
Client connects to server on a port, again using a socket.
So all you need is ONE socket for each side. If you use both TCP and UDP, you need of course two of them, because a socket can only handle one protocol at a time. But you don't need to listen at your client. Once your *client socket* is successfully connected to the *server socket*, you can send AND receive data on the same socket.
If I got this right, while a TCP socket is connected to the server, is can be used both for sending and receiving messages, although not in the same time.
Exactly, it's bi-directional. Well, what do you mean by "same time"? You can read data and immediately send data through the socket in a row.
Do I have to use two separate sockets, one sending and one receiving, connected to the same address and port?
No. Connect your TCP socket to the server, then you can read from and send through it.
It seems even more problematic with UDP sockets since it needs to be bound to a port, and (according to the SFML 1.3 tutorial) it is the same thing as listening to the port (written in parenthesis commented in the code).
That's only partially true. UDP, but also TCP!, sockets must all be bound to a port. In case of a server, you choose the port yourself (webservers for example use TCP port 80). Now if a client connects, it binds its socket to a local port, mostly random, and given by the operating system. If the connection is established, both sockets can communicate with each other through the ports.
When sending UDP packets, you kinda initiate a connection -- not really, because UDP doesn't use "real" connections like TCP. The important part is that your router keeps that in mind, i.e. it will store the port YOU used to send the UDP packet and source IP (your LAN IP). Now when a packet from the server comes back, addressed to your local port, it gets routed to your interface.
In short words: You don't need to forward/open ports on the client-side when talking to a server, whether it's TCP or UDP.
Edit: Look at the diagram, it shows how a connection roughly looks like:
*click*Daazku:
That depends on what you're developing. Server applications should be written to block, thus not consuming all the CPU time. Therefore you should use a selector, so that your application only runs when needed.
Actually the same goes for client applications (games). One solution could be to separate the networking part into an own thread, just for reading from sockets. This way you can both limit your framerate (takes pressure off the CPU) and keep your networking routines in a blocking state, which consumes no CPU time at all. Polling is generally a bad idea.