Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Kryonet] How to force client to disconnect?  (Read 1755 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Posted 2012-06-22 12:36:37 »

Hello everyone! I am developing a StateBasedGame in Slick2D and i want to make it singleplayer and multiplayer.

My question is:
Is there any way to make the client DISCONNECT (not close) when exiting from the MP state?

Getting a project done is by far the most hard thing in game development.
Offline matheus23

JGO Kernel


Medals: 107
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2012-06-22 12:45:08 »

I don't know any way from the api, but you could just send a "You have to disconnect" message.

I'd do it that way:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class Message {
    // Use these to send messages of different "types".
   // With bytes you can only have 255 different Messages.
   // Use "int" for example, to enable ~4.294.967.300 different Messages.
   public static final byte DISCONNECT = 1;
    public static final byte WHATEVER = 2;

    // The Message itself, so either 1 or 2.
   public byte msgValue;
}

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #2 - Posted 2012-06-22 13:32:30 »

That's it! My problem was that i was looking for a disconnect function in client/server, and i found it in connection.

Thanks!

Getting a project done is by far the most hard thing in game development.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #3 - Posted 2012-06-22 15:07:46 »

I don't know any way from the api, but you could just send a "You have to disconnect" message.

I'd do it that way:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public class Message {
    // Use these to send messages of different "types".
   // With bytes you can only have 255 different Messages.
   // Use "int" for example, to enable ~4.294.967.300 different Messages.
   public static final byte DISCONNECT = 1;
    public static final byte WHATEVER = 2;

    // The Message itself, so either 1 or 2.
   public byte msgValue;
}

With int and Kryo's variable length encoding you get 0-128 in 1 byte, 0-16384 in 2 bytes, etc. If you want to save space, you can use a different class for each message. In the above, KryoNet will send 1 byte (variable length int) to identify the Message class, then 1 byte for msgValue. You probably want to use separate classes anyway, as each class can have different fields. So I would use this:

1  
public class Disconnect { }


When the client receives that, she disconnects.

Offline matheus23

JGO Kernel


Medals: 107
Projects: 3


You think about my Avatar right now!


« Reply #4 - Posted 2012-06-22 15:12:35 »

Didn't knew that... Thanks creator of Kryo Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2012-06-23 03:01:44 »

That's it! My problem was that i was looking for a disconnect function in client/server, and i found it in connection.
Note Client extends Connection, so you can do client.disconnect().

Didn't knew that... Thanks creator of Kryo Smiley
Cheesy

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (32 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (32 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!