Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (764)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4
  ignore  |  Print  
  GNetLib V0.0.0.3 (A Simple Java Networking Library)  (Read 80177 times)
0 Members and 1 Guest are viewing this topic.
Offline VIrtueeL
« Reply #60 - Posted 2014-10-23 11:12:39 »

i sent you msg and stuff!
please add me on skype and help me with this networking
i will all credits to you throw my youtube channel when i
do tutorials
all i want to learn is how to get the clients to see etch other and see etch other
move after that i have learned that and it will be easyer for me to understands this packet things
Smiley ty

Skype: tomastero

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #61 - Posted 2014-10-23 21:09:44 »

Is there a way to kick one specific client from the server(I'm using ClientShutdownPacket by the way)?

The ClientShutdownPacket has been pre-programmed into the library: (Meaning you do not need to create/add data entry's to it)
1  
2  
3  
4  
5  
// Pre-programmed packet: org.gnet.packet.ClientShutdownPacket class
public ClientShutdownPacket() {
   super("ClientShutdownPacket", 1);
   super.addEntry("shutdownClient", Boolean.TRUE);
}

You'll need to revise your code like so: (Note line 15 on how to properly send the packet/handle packet events)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
if (packet.getPacketName().equals("UserPacket")) {
   users.add((String) packet.getEntry("username"));
   String test = users.get(0);
   System.out.println(packet.getEntry("IP"));

   boolean kick = in.nextLine().contains("kick: ");
   if (kick) {
      String[] x = in.nextLine().split(":", -1);
      System.out.println(x[0]);
      System.out.println(x[1]);

      // HERE: Send the packet to disconnect the client.
      client.sendPacket(new ClientShutdownPacket());
      return; // packet handled.
   } else if (!kick) {
      // If you've received the packet, and kick = false, still 'return'.
      return; // packet handled.
   }
}

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #62 - Posted 2014-10-23 21:14:43 »

Or be able to add/remove outputstreams that msgs are sent to. By default System.out/err, can add more or remove them.
Thank you so muchhh  Grin Grin Grin Grin Grin Grin
You're welcome ^__^
Would be a nice feature to have also @BurntPizza/robocos.

all i want to learn is how to get the clients to see etch other and see etch other
Very easy process, I'll try and help you within the next few days when I get some free time as you've made a YouTube video for me already which is greatly appreciated <3

Add me on skype: waleed.ahmad.ghazal
please add me on skype and help me with this networking
Skype: tomastero
Added both of you ^__^

Checkout my new easy to use java networking library: GNetLib
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline robocos987
« Reply #63 - Posted 2014-10-24 01:25:51 »

But still, how do I kick a client individually without having to kick all the clients?

Your mom is so fat, the recursive function calculating her mass caused a stack overflow Tongue
Offline VIrtueeL
« Reply #64 - Posted 2014-10-24 04:59:15 »

put players that you want to kick in hashmap or arraylist
then get ex

name
id
Player
and then kick all players in that arraylist or hashmap

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #65 - Posted 2014-10-24 05:40:40 »

without having to kick all the clients?
Can you elaborate on this?
(Possible bug?)

But still, how do I kick a client individually without having to kick all the clients?
Basically you would do what VirtueeL suggested:

  • Create some sort of List that will be used to store the players.
  • Each time a player connects add him to the list. (vice-versa for disconnecting)

You now have control over any client on the list.

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #66 - Posted 2014-10-27 03:30:58 »

V0.0.0.3 is finally here, decided to completely re-write it again and have fixed/added a few things.

Sorry I couldn't fit in UDP in this update.  Cranky

V0.0.0.3 will include:
I've added support for obtaining debug/error messages - As requested by robocos987
I've added a ServerMonitor GUI. (Advanced statistics)
Fixed all memory leaks/non functional events/variables.
A re-written event handling system.
A functional ClientShutdownPacket to kick individual clients.
Each client that connects now has their own generated UID.

Download link: Download GNetLib.jar
New code required to create the server: view pastebin
New code required to create the client: view pastebin

I will add a tutorial to the OP on how to set up a server/client along with handle events and enable the new ServerMonitor.
EDIT: Done, also uploaded V0.0.0.3 source into OP.

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #67 - Posted 2014-10-29 04:31:35 »

I've decided to keep track of project bugs in the OP ^__^ (Now visible with fix dates)

- On another note, I'm making a multiplayer demo game with GNetLib XD (Client/Server)

EDIT: During my progress of the multiplayer demo I added these methods in the demo than thought.. why doesn't the server have these? lol Roll Eyes.

Update to GNetServer class: (OP download links have been updated to include this update)
1  
2  
public void sendToAll(Packet packet); // Send to ALL online clients
public void sendToAllBut(ClientModel who2NotSend2, Packet packet); // Send to ALL besides 'who2NotSend2'

Checkout my new easy to use java networking library: GNetLib
Offline VIrtueeL
« Reply #68 - Posted 2014-10-29 11:42:50 »

thats a really good function for sending movement and other stuff like msg to all players
really good! keep up bruh! cant wait for the demo =D

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline VIrtueeL
« Reply #69 - Posted 2014-10-31 21:59:12 »

when is the demo coming =D

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #70 - Posted 2014-10-31 22:07:11 »

when is the demo coming =D

Thanks for asking ^__^

Hopefully within the next week, I'm rather busy with appointments and such at the moment :/

Demo has been started Cheesy and core functions are working, just need to implement a few more things before release ^__^

Demo will include:
A multiplayer server along with a client.
Clients will be able to see all other online clients at their current position along with their UID above their head.
(As demo will not include a registration/login system so no usernames yet Tongue)
Clients will be able to click a client in the game world and have the option to PM them.
Maybe a public chat system ^__^

Any other suggestions for what to include in the demo that GNetLib offers?

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #71 - Posted 2014-11-01 20:44:49 »

Just had to interrupt my development of this demo to post, as this is my first multiplayer game ever.
(And it's using my own networking library which is also my first, so WOOT XD) Pointing Pointing

What the demo now contains:
You can see every player as they join the server. (Initial location)
You can see every player as they move and vice-versa for you. (Current location)
You can see every players UID above their head. (No username implementation in demo)

Here's a YouTube video of the multiplayer demo brought to you by your very own JGO user VIrtueeL:
(If the video is too small in this thread: Watch on YouTube in HD/fullscreen -> leave a like & comment / sub if you wish Roll Eyes)

<a href="http://www.youtube.com/v/bXU_pvAXUIs?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/bXU_pvAXUIs?version=3&amp;hl=en_US&amp;start=</a>

NOTE: Demo still has a few minor glitches that need to be fixed before being posted ^__^

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #72 - Posted 2014-11-04 02:41:14 »

New updates to GNetLib:
You no longer have to enable the ServerMonitor prior to starting the server.
(As before when server.start() was called it would initialize / show the ServerMonitor)
You no longer have to do this, you can now enable/disable the ServerMonitor on the fly. Cheesy

I've also changed the length of the generated UID for each client to 4. (Think it was 9 before?)
In future updates I'll enable the ability for the user to decide the length of the UID the server generates for each client.

New methods in GNetServer class:
1  
2  
3  
4  
5  
// Will initialize and show ServerMonitor.
public void enableServerMonitor();

// Will dispose of ServerMonitor.
public void disableServerMonitor();

Also added a Boolean to GNetServer class to keep track of whether or not the ServerMonitor is visible:
1  
public boolean isServerMonitorVisible();

ON ANOTHER IMPORTANT NOTE:
I accidentally deleted the multiplayer demo from my eclipse workspace.........
Totally wasn't thinking, so I'll be re-writing the demo and it will be more cleaner/faster/graphically enticing.

Checkout my new easy to use java networking library: GNetLib
Offline TehJavaDev

JGO Knight


Medals: 17
Projects: 3
Exp: 7-9 months


Java is so dope they wanna >:D


« Reply #73 - Posted 2014-11-10 21:47:44 »

Sorry development's been paused, dealing with medical issues IRL at the moment.

Just figured I'd let people know ^__^

Checkout my new easy to use java networking library: GNetLib
Offline VIrtueeL
« Reply #74 - Posted 2014-11-25 12:28:50 »

i still have the demo if you want it?

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline Focan

Junior Newbie





« Reply #75 - Posted 2014-12-30 10:13:55 »

Hello people ,

I'm Focan and im a programmer with games development hobby Smiley

Im programming a game with libgdx libraries and i finished the single player mode , last weekend i started to program the multiplayer mode with gnet library , but i have a lot of problems with this library.


i can't send packets from client to server unless server sends a packet to a client , i can't send packets manually from client to server?.

i generated a loop between client and server , generating packets to update player coordinates in server and server responds asking again for new coordinates , it works but the memory consumition is too hight and sends too much packets per frame , how i can slow down this loop?.

Sorry for my english... Sad

And thank you for answers. Smiley
Offline VIrtueeL
« Reply #76 - Posted 2014-12-31 14:09:47 »

fixed timestep then only send 1 packet with the players movement every 60f
then callucultate what direction hes traveling or something =/

dont send so manny packets at the same time its rly bad =D

i do devlogs and i do tutorials check em out
https://www.youtube.com/user/InidDevo
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #77 - Posted 2014-12-31 14:19:21 »

MMOs send about up to 10 packets a second for position changes. Don't remember where I read this.

Offline Focan

Junior Newbie





« Reply #78 - Posted 2015-01-11 17:07:03 »

Hi people , im in a little trouble with gnet lib , im getting the errors

StreamCorruptedException: invalid type code: 73

StreamCorruptedException: invalid type code: 00

and the error is getting at lines 92 and 49 of GnetClient.java class

In the client Side where im passing this packet:

Packet paquete = new Packet("jugadorTocado", 1);
paquete.addEntry("valor",cliente.otherPlayers.get(i).clientId +":"+ melePj.power );
cliente.servidorHost.sendPacket(paquete);

i tract the packet in the server like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
if(arg1.getPacketName().equals("jugadorTocado"))
         {
            for(int i =0; i < server.getClients().size(); i++) // i send the packet to all the clients , i tryed with SendToAll() function but got same error
            {
               try
               {
                  if(server.getClients().get(i).getUuid() == Integer.valueOf(String.valueOf(arg1.getEntry("valor")).split(":")[0]))
               {
                  Packet paquete= new Packet("jugadorTocado", 1);
                  paquete.addEntry("valor", arg1.getEntry("valor"));
                  server.getClients().get(i).sendPacket(paquete);
               }
               }
               catch(NullPointerException e)
               {
                  System.out.print("error null pointer en reenvio de paquete de daño de player a otros players");
               }
               catch(IndexOutOfBoundsException e)
               {
                  System.out.print("error out of bounds en reenvio de paquete de daño de player a otros players");
               }
                     
            }
         }

and when i recieve it from other player i tract like this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
int lifeDept;

 if(arg1.getPacketName().equals("jugadorTocado"))
   {
      try
      {
                  lifeDept+= Integer.valueOf(String.valueOf(arg1.getEntry("valor")).split(":")[1]);
      }
      catch (NumberFormatException e)
      {
      lifeDept=0;
         System.out.print("\n error de parseado de daño de player enemigo");
      }
   }

Something wrong in my code?
Offline CopyableCougar4
« Reply #79 - Posted 2015-01-11 17:10:23 »

StreamCorruptedException: invalid type code: 73

StreamCorruptedException: invalid type code: 00

I believe those errors are related to serialization. The serialization over a network may be causing issues if serial version ids and actual class data doesn't match up.

I browsed through GNetLib and all packets are serialized across the network, which means that the serialization is the library's job, so I don't think you did anything wrong in your code but I'm not sure.

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Focan

Junior Newbie





« Reply #80 - Posted 2015-01-11 18:41:59 »

yes i guess that the error can be in the lib , but in my game i implemented a lot of packets and when im playing the game in online mode they are a lot of packets sending and receiveing between server and clients , how can produce always the error this packet and not the other types of packets that i use?.




Thank you for response Smiley
Offline CopyableCougar4
« Reply #81 - Posted 2015-01-11 22:36:04 »

How often is the exception thrown? Is it for every packet or just occasionally?

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Focan

Junior Newbie





« Reply #82 - Posted 2015-01-11 23:09:53 »

i test all packets manually:

i move the player for test the position packet --no problem
i trow magic spells and trow arrows to test the enemyBullet packet -- no problem
i test the weapon kick damage packet -- after a lot of tries fails and throw exception.


The strange in my fail is that the system works well with a lot of conflictive packets , but in 1 fail throwing exception.


i dont know if can be the error but , can be that i put all info in 1 entry and the conversions of object can crash the object?


Thank u a lot Smiley
Offline CopyableCougar4
« Reply #83 - Posted 2015-01-11 23:14:20 »

i test the weapon kick damage packet -- after a lot of tries fails and throw exception.

Would you be able to post a snippet of how you send a weapon kick damage packet?

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Focan

Junior Newbie





« Reply #84 - Posted 2015-01-12 06:55:14 »

of course Smiley :

1  
2  
3  
Packet paquete = new Packet("jugadorTocado", 1);
paquete.addEntry("valor",String.valueOf(cliente.otherPlayers.get(i).clientId) +":"+ String.valueOf(melePj.power));
cliente.servidorHost.sendPacket(paquete);


I include in the packet the ID of the client who do damage(int) and the power of damage(int).
cliente is a clientGame object , that gives the clientModel class and listener.
servidorHost is a ServerModel that have the configuration of the server to send him packets.
Offline Focan

Junior Newbie





« Reply #85 - Posted 2015-01-13 12:00:44 »

ok people , i located the fail of my code , it seems that if server receive a packet , cant use the information of this packet and resent a copy of this packet to other clients , i modified the confictive packet to avoid this error and now dont crash the client , but i dont know how the lib cant resend a packet from a client to a other clients.



Offline Hadriel

Junior Newbie


Exp: 1 year



« Reply #86 - Posted 2015-01-13 15:39:21 »

I'm Currently Testing your Library, and i prefer this to Kryonet for testing / understanding how networking goes. However, i like modular games, and as i was reading your source code, i noticed this your function :

public void addEventListener(final ClientEventListener clientEventListener) {
      this.clientEventListener = clientEventListener;
   }

i think it's not correct to call this "add" since it's a set. i'm wondering if you can build a system that forwards packets to multiple listeners, like :

addEventListener(new ChatListener());
addEventListener(new GameInputsListener());
addEventListener(new AnotherPluggedService());

then send a custom Packet that ChatListener can handle, it's read by ChatListener, then consumed (pretty much like an event system ? Cheesy)
if it's a GameInputListener (e.g) then ChatListener just doesn't handle it, and Packet is forwarded to GameInputsListener.

sorry for the bad English.
PS: That could be really awesome for plugins/modules for games using this library.
Offline KudoDEV

JGO Ninja


Medals: 79
Exp: 6 years


Game Dev Hobbyist


« Reply #87 - Posted 2015-01-13 15:49:23 »

Quote
Customization of serialization

Kroynet does provide custom serialization: Here

But besides that this looks great!

Offline Focan

Junior Newbie





« Reply #88 - Posted 2015-01-16 19:42:49 »

hi people:

anyone tried to redirect from server a packet sended by one player to all players except him?.


I want to comunicate to the other players that i created a bullet , and when client game creates the bullet automatly send a packet to the server with coordinates of the bullet , the server have to redirect this packet to all players in server except player who sended the packet , i tried to do:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
@Override
protected void packetReceived(ClientModel arg0, Packet arg1) {
if(arg1.getPacketName().equals("newBullet"))
   {
            Packet packet = new Packet("bullet",3);
            packet.addEntry("client",arg1.getEntry("client"));
            packet.addEntry("x",arg1.getEntry("posx"));
            packet.addEntry("y",arg1.getEntry("posy"));  
            server.sendToAllBut(arg0, packet);
   }
}



is simple but when i test with multiple tries the client crash with stream corrupted exception. code 00 or code 73

Is correct my way to comunicate from 1 client to others?


Thank you  Smiley
Offline Hadriel

Junior Newbie


Exp: 1 year



« Reply #89 - Posted 2015-01-19 09:54:19 »

Networking can basically be like :

Client sends "i shoot"
Server (calculates the location / rotation of bullet)
Server broadcasts "created bullet @ (x,y,r)"
Client creates bullet
...

But this way the game will appear laggy for all the clients (try it on a multiplayer game on Age OF Empire II e.g.). The fact is that every single action for the player is going to be asserted by the server.
Facing this lag issue, the solution is to locally admit your action is valid. e.g :

Client creates bullet + sends "i shoot"
Server tests validity of the input/action
Server broadcasts everyone BUT THIS CLIENT "new bullet @ (x,y,r)" [this way action is valid]
OR
Server answers Client "delete this bullet" [this way, action is not valid]

---
I don't know if there is an implementation of broadcasting on server, but my way to handle this would be in the ServerListenner class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
public class PersonnalListenner extends ServerEventListener {
         
   private List<ClientModel> clients = new List<ClientModel>();
   
   protected void packetReceived(ClientModel client, Packet packet) {
     
   }

   @Override
   protected void errorMessage(String msg) {
     
   }
   
   @Override
   protected void debugMessage(String msg) {
     
   }
   
   @Override
   protected void clientDisconnected(ClientModel client) {
      clients.remove(client);
   }
         
   @Override
   protected void clientConnected(ClientModel client) {
      clients.add(client);
   }
   
   public void broadcast(Packet p) {
      //sends the packet to each client connected
      for(ClientModel c : clients){
         c.sendPacket(p);
      }
   }
   
   public void broadcastExcepted(ClientModel excepted, Packet p) {
      for(ClientModel c : clients){
         if(c == excepted){
            continue; //skips the "broadcast" behaviour if ClientModel in param is encountered
         }
         c.sendPacket(p);
      }
   }
}


I didn't try to run this code (i'm not working over this for now). Also think about synchronizing every piece of code arround accessing "clients" list.

Sorry for the bad english Tongue. I hope i'm understandable.
Pages: 1 2 [3] 4
  ignore  |  Print  
 
 

 
EgonOlsen (590 views)
2018-06-10 19:43:48

EgonOlsen (694 views)
2018-06-10 19:43:44

EgonOlsen (478 views)
2018-06-10 19:43:20

DesertCoockie (831 views)
2018-05-13 18:23:11

nelsongames (1026 views)
2018-04-24 18:15:36

nelsongames (1083 views)
2018-04-24 18:14:32

ivj94 (1664 views)
2018-03-24 14:47:39

ivj94 (590 views)
2018-03-24 14:46:31

ivj94 (1500 views)
2018-03-24 14:43:53

Solater (568 views)
2018-03-17 05:04:08
Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46

Deployment and Packaging
by philfrei
2018-08-19 23:53:08

Deployment and Packaging
by philfrei
2018-08-19 23:50:04

Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39
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!