Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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 1192 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:
server:
http://pastebin.com/r9AdU2BY

client and dataPackage:
http://pastebin.com/ahgRRhtW
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 '127.0.0.1' 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 127.0.0.1 (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: 269
Projects: 11
Exp: 2 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.

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 Knight


Medals: 40
Exp: 6 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  
 
 
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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