Sockets

Discussion in 'Plugin Development' started by gamemster2468, Jul 11, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    gamemster2468

    Hi there,

    So I am trying to make a system where I could send (for example a command) to another server. I was hoping to accomplish this using sockets, but I'm having a little trouble.

    I do not whether to use Client (Socket class) to Server (SocketServer) or to use Server to Server if this makes sense.

    Hope someone can help,

    Edit:

    So with some searching I think I know what I'm going to do:

    For each server I am going to open up a new ServerSocket using the server's address and port, and than wait I guess have a thread that waits for data to be sent from another server.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 11, 2016
  2. Offline

    mythbusterma

    @gamemster2468

    One of the servers needs to be the client and the other the server, that's just how TCP is designed. Someone has to initiate the connection. That being said, both of them could be acting in both roles, but I don't see why this would be practical.

    What exactly are you trying to do? Usually in these sorts of scenarios, a "leader" will be elected, and that will be the server. It would certainly make the architecture simpler.

    Just because one is the "server" and the other the "client," doesn't mean that information can't be exchanged in both directions, as TCP is a bi-directional communications protocol (assuming you're using TCP [which you should be]).
     
    gamemster2468 likes this.
  3. Offline

    gamemster2468

    @mythbusterma

    Basically I want to be able to pass strings to another server, and then listen for that information (so a check) and then be able to do something. So for example:

    If I were to have a game server, on game stage, player join, player leave, etc I would like to store the data in redis, and send a message to the hub server, saying basically "hey, update the server sign of [blank]" if this makes sense. This is just one instance of what I want to do, I plan to also send commands and messages to other servers. I do know that this can be accomplished through redis PUB/SUB feature, but quite honestly, I've been searching for days trying to get some good tutorials but no luck, so I decided to turn to sockets.

    Hope you can help and thanks for the reply! :)
     
  4. Use a mysql server and maybe trigger events. Much easier
     
  5. Offline

    mythbusterma

    @gamemster2468

    Yes, you could use Redis for this, but as I said in the other thread like this, no need to tack on unnecessary dependencies. If there's actually a need for this to be a queue, then you're going to need Redis, which I guarantee is going to piss off users. If you can deal with only sending updates when both are online, then send them directly to each other.


    @FisheyLP

    No, no, no, and no. Using RDMS's as message queues is an anti-pattern and should be avoided. http://mikehadlow.blogspot.com/2012/04/database-as-queue-anti-pattern.html
     
  6. Offline

    tylersyme

    Well ok, so you are wanting a way for two minecraft server to communicate. Just like most things there are many ways to solve the problem. In the end, it does not technically matter which minecraft server is being considered the "Server Socket" and which is being considered the "Client" just so long as both roles are fulfilled. Here is what I would suggest.

    So let's say you have a plugin dedicated specifically to the communication between these two or more servers (or you could tack this functionality onto an existing plugin if you wish).
    Let's also say that each of your minecraft servers are currently down. So you startup the first server.
    This activates the communication plugin which immediately checks to see if the other server(s) are online.
    In this case, no other server is online, so right away it declares itself to be the server (ServerSocket).
    Every other server which is turned on after the first one will search until it finds this "main server" and then connect to it as a client (Socket).

    There are a number of ways you could allow minecraft servers to "detect" each other.
    1. You could simply give the plugin a hard coded list of the other server's IPs (probably not the best option in the long run).
    2. Use a shared document which stores each of the server's IPs (you would still need to manually enter new server IPs)
    3. Somehow use bungee in coordination with your plugin to manage server IPs (no idea what that would look like)

    There's gonna be a ton of little issues that you would have to figure out as you reach them, but I hope this helped :)
     
Thread Status:
Not open for further replies.

Share This Page