Maybe you dont understand how sockets actually work. The "server" is really just an application with an open socket which can accept connections. The "client" is basically the same thing thing except its distributed. Each client has their own socket in which they connect to the server's socket, so the server always knows who is sending data to it. The same thing applies to clients. If you have a p2p thing setup with SFML, the client will know which socket sent them data, be it the server or another client.
As for your problem, it probably has something to do with your threading. You arent synchronizing the data in anyway so theres probably a race condition there. Also you should avoid using global variables.