Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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  
  lan games in java  (Read 5792 times)
0 Members and 1 Guest are viewing this topic.
Offline PRW56

Senior Newbie

« Posted 2013-01-31 06:22:57 »

Just wondering if anyone would know a good tutorial for lan networks in java, I understand sockets and the like, as well as the whole concept of doing say collision detection on one computer and sending the updated data to all the clients, but the only actual server and client java program I could find a tutorial for creates a server that crashes immediately after the client disconnects, I don't understand the (coding) difference between the tutorial he showed and a lan network program, or even whether or not his was already lan to begin with. Any tutorials or help would be nice, ty

here is the code for that tutorial I found:

client and dataPackage:
Offline GabrielBailey74
« Reply #1 - Posted 2013-01-31 06:59:33 »

Just sent you a PM.
But, regarding not knowing whether the examples were 'LAN' or not:
I believe LAN is just connecting both computers to the host address '' while 1 or another computer hosts the server on that same address.
So a non LAN Server/Client pair would just be the server hosted off a different address than (So it would be a real IP).

Offline Alan_W

JGO Knight

Medals: 8
Projects: 3

Java tames rock!

« Reply #2 - Posted 2013-01-31 07:19:39 »

LAN games are on the same network segment.  This means they will all have addresses of the form XXX.XXX.XXX.YYY where XXX is the same for all the clients and server.  That means no problems getting past routers and you can use broadcast packets to transmit your client data to all other clients in one go (if you use UDP rather than TCP), if you are running peer-peer rather than client-server.

The nice thing about LAN games is that you can build in automatic discovery of clients, so user setup is a breeze.  Also, because ping is low, less effort is required for lag compensation, so FPS games run really well.

Obviously LAN games can only be run on computers at the same location (limited by the maximum length of an ethernet cable run) so no good for internet play.  On the other hand, since you are only playing with friends, there is no need to build in anti-cheat code (unless you have really sneaky friends)

The first thing to decide is client-server or peer-peer.  Then decide TCP/IP versus UDP.  For FPS LAN games I would suggest UDP broadcast peer-peer.  For role playing games TCP/IP client-server.

Got to go....

Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #3 - Posted 2013-01-31 07:20:08 »

Sockets work the same whether it's LAN, IP, or localhost.

Offline 65K
« Reply #4 - Posted 2013-01-31 07:49:14 »

but the only actual server and client java program I could find a tutorial for creates a server that crashes immediately after the client disconnects
A bad example of what never to do: leaving catch blocks empty
Just print the stack trace for caught exceptions to find the reason of the crash.

Lethal Running - a RPG about a deadly game show held in a futuristic dystopian society.
Offline PRW56

Senior Newbie

« Reply #5 - Posted 2013-01-31 07:59:37 »

I chose the wrong wording, the server program does not crash (i.e. close?), it freezes, i have to open up task manager to shut the thing off.
Offline Oskuro

JGO Ninja

Medals: 77
Exp: 10 years

Coding in Style

« Reply #6 - Posted 2013-01-31 13:38:16 »

You could look up the code for a simple chatroom, and make sure the network functionality is robust enough before integrating it into your game.

After all, network communication is no different from a simple chat, you just process the messages differently (not to mention you'll want to be able to send chat text too).

As for the mentioned LAN/WAN difference, if you have a TCP/IP capable client/server architecture, you have both options. The only relevant difference, as has been mentioned above, is scanning for servers, which on a LAN can be easily managed because you know the IP range of all devices on the same subnet.

For WAN (Internet) play, either players need to know their connection IP (your game could provide this information) and manually enter it to connect, or there needs to be a master server that players connect to in order to find open games (which could be set up easily on a website, but it might require upkeep).

Providing direct IP capabilities is important, as you might be on a LAN, but on different subnets, which could render your server search function useless.

If I may go on a tangent, this issue really irks me about gaming today. Despite what publishers claim, all games are perfectly LAN capable, as they have TCP/IP capabilities, yet in increasingly many cases they restrict this by forcing the user to rely on the online master server for matchmaking, which means that, once the owners inevitably turn the server off, the game's online mode becomes useless.

I find it sad that old games had more flexibility just by allowing users to manually type the server IP address than current games.

Tangent over! Cheesy

Pages: [1]
  ignore  |  Print  

hadezbladez (739 views)
2018-11-16 13:46:03

hadezbladez (377 views)
2018-11-16 13:41:33

hadezbladez (729 views)
2018-11-16 13:35:35

hadezbladez (191 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2618 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

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 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‑
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!