Server-side LINUX client-side C # socket connection (Game Anti-cheat) RRS feed

  • Question

  • Hello,

    I've been studying the relationship between c # - linux for a while.What I want to do is make a connection between the program written in c # and the linux server. I am able to send to linux server with the c # codes I use. But I cannot send to program from linux server.

    I want to do;

    Game Player => Game connect => get the player's ip address(sample:


    send socket (, port, package)=> if the program is open => reply:(hello,I am and the program is running)

    If Roger;

    1- player connects to the game

    2- the server performs a socket connection to the player's ip address.

    3- if the player responds

    4- player continues to play or kick

    Sunday, November 17, 2019 12:44 PM

All replies

  • This will in general not work for the vast majority of players.

    The reason is that most of the time the player's computer will be located in a network with private addresses (such as 192.168.x.x) which connects to the Internet through a Network Address Translation (NAT) gateway. Your server will receive the connection request from the public address of the NAT gateway (such as 88.x.x.x), NOT from the real address of the playing computer (192.168.x.x).

    The NAT is intelligent in that when a user connects out from the private address the NAT memorizes the address (source ip and port) from that request, translates the address (and possibly changes the port), and sends it out to the server. When the server responds, the NAT looks up in its table which was the address/port that it sent out, translates back to the address/port that initially made the request, and sends the reply to the original requestor.

    However, if your server tries to open a connection directly to the address from which the original request came, which will be the public address of the NAT, then the NAT will not find in its table any entry that maps to such a connection, and will drop it without sending it to the PC in the internal network. Thus, your server will not be able to connect in this way to the player's computer.

    Sunday, November 17, 2019 2:08 PM
  • So this idea is impossible?
    Sunday, November 17, 2019 4:34 PM
  • Well, not exactly "impossible". You could enable it only for users that are not behind NAT or a firewall (which would severely limit the number of users) or for users who are able to configure reverse-NAT in their router (which will also limit the number of users who can do it).

    But if you want something user-friendly that can be used by all users, then I'd say "forget it". Stick to using only connections that are initiated from the user's side, and just send responses from your server using the connection that was initiated by the user.

    Anyway, it would not be a viable solution for game anti-cheat if that was what you wanted it for. Even if the user's address is exposed to the server, it is still possible for the user to interpose a proxy in between so the server would see the connection coming from the proxy and would connect to it following your design. So the proxy would still be able to intercept and manipulate the communication. A better solution would be to encrypt and sign all packets exchanged between the client software and the server so that they cannot be read or modified "en route".

    Sunday, November 17, 2019 4:56 PM
  • I'm sorry for my bad english. Which is the right solution? How can I follow this? In order to send packets from the player to the server, I need to know which server it connects to. which is the right way?
    Sunday, November 17, 2019 7:44 PM
  • In order to send packets from the player to the server, I need to know which server it connects to. which is the right way?

    That's what the DNS system is for. You use DNS to map your server's IP to a domain name. Then you get your players to connect to that name, and the network infrastructure will resolve it automatically to the address of the server.

    If you have several servers and any of them can be chosen indifferently, then you can use DNS round-robin (which means add several IPs for the same name). Or, f you need to assign a specific server to each client, you write your code to first connect to a "master" server which tells the client where to connect to, and then the client opens the connection to that second server.

    Sunday, November 17, 2019 8:01 PM