PUB/SUB Help

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

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

    gamemster2468

    Hi there,

    I am currently having some trouble with this code:

    http://hastebin.com/iyugefemih.java

    This is my first time working with redis' PUB/SUB feature, and I don't really know what is happening. There are no stacktraces, it's just, when the plugin enables, it freezes. Yes, I know this is because I am doing it on the main thread, but even if I run it async (Which I have) it still does not work.

    Hope someone can help! Thanks
     
  2. Offline

    mythbusterma

    @gamemster2468

    Didn't we go over this before? Don't bother with Redis. I'm pretty sure it just halts waiting for a message.
     
  3. Offline

    gamemster2468

    @mythbusterma I know we went over this, it's just, you know, seems to me like the best solution as I'm already using redis for some other data that I'm storing.

    Hm, interesting point. I can't say that I've heard of that happening, but thanks for your reply!
     
  4. Offline

    mythbusterma

    @gamemster2468

    That's just speculation on my part. I wouldn't take what I say as fact. You'll have to read the documentation of the Jedis to figure that out.
     
    gamemster2468 likes this.
  5. Offline

    gamemster2468

    @mythbusterma

    Alright, so I think it's time to talk about sockets. I just made a simple plugin that sends messages to other servers, like I want it to, without using PUB/SUB and I have to say it's pretty nice. I do have a question, though:

    If I try to use the server's port, it says that there is another server on the port. I guess I can kinda understand this, but here is what I don't get: Why can't I just send data to the minecraft server? Why do I have to create a new SocketServer and have to figure out a different port to make sure I don't run into the "Address is already in use"?

    I don't know if this really makes sense, hope I explained it somewhat okay.

    Edit: I am attempting to make a cross server chat system. Just incase so I can know if this is the best way to do it.

    Thanks for all of your help.
     
    Last edited: Jul 21, 2016
  6. Offline

    mythbusterma

    @gamemster2468

    I would definitely go with a direct socket connection for this, simply because the publisher and subscriber queue makes more sense for things that are long running, need to retry on failure, etc. For cross-server chatting, simple best effort delivery makes the most sense.

    Basically, it boils down to this:

    When the server starts up, it starts listening on the Minecraft server port (25565 by default) and expects clients to connect on that port. Internally on the server, it handles incoming packets using NeTTY handlers, and expects any clients that connect to use the Minecraft protocol (documented on wiki.vg). Trying to create something else that listens on that port is going to make the OS upset, because it's already is handing any traffic that comes in on that port to the Minecraft server socket. This is what causes the "address is already in use" error. I realise this is an extremely simplified overview of the concepts, but that should be enough to figure out what I mean.

    To avoid this, you need to listen for traffic on a different port (or I suppose you could do a different IP, but that would be significantly more difficult to set up).
     
Thread Status:
Not open for further replies.

Share This Page