Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  General networking questions  (Read 1165 times)
0 Members and 1 Guest are viewing this topic.
Offline samcp12

Junior Member


Medals: 1



« Posted 2013-07-13 00:05:40 »

So, the way I've been sending objects to a server is by creating the objects class in both the client project and the server project then just reading them in through a stream, is this the correct way to do so?

Another question I have is, If I were to create a simple multi-player game where a player would connect to a server and a new player object would be created, would I just create the server in a different project as usual, send the necessary data to the server, then have the server send back information that needs to be updated such as play positioning?

Last question is, for Peer-to-Peer where one player is the host, in terms of how the server and connections made, how exactly does it work, by which I mean when a new client joins where does it connect to?

Any help is appreciated!  Cool

Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


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


« Reply #1 - Posted 2013-07-13 00:14:24 »

Peer-to-Peer is Client-Server where one of the 'clients' is a server in disguise.

Offline Stranger

Senior Member


Medals: 6



« Reply #2 - Posted 2013-07-13 08:16:47 »

You may want to look at the posts:
http://www.java-gaming.org/topics/p2p-multiplayer-game/29920/msg/275708/view.html#msg275708

http://www.java-gaming.org/topics/kryonet-p2p-through-the-server/28985/view.html

Anton
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline samcp12

Junior Member


Medals: 1



« Reply #3 - Posted 2013-07-14 18:45:17 »

So, I was thinking it would go like this, the first player would start a new game, this would then create a server at the port the user enters, the game would then wait for a connection from a client which would then start the game, so in turn although there would be 2 players, one is the actually the server and the other is the client. Am I on the right track for this? Thanks!
Offline nerb
« Reply #4 - Posted 2013-07-15 04:48:56 »

Yes it sounds like you are on the right track.

Assuming you are using java sockets, the player acting as the server will create a ServerSocket on the desired port. The player acting as the client then connects using a Socket to the server's IP and port.

If the player acting as a server is sitting behind a router however, they will more than likely have to enable port-forwarding for the particular port that your game is running on. Although this would be up to the player to sort out, as the method varies for different routers. I'm not sure if there is any way around this; if there is perhaps someone more experienced than me can fill you in.

EDIT: (I always edit my posts...  Clueless) Just food for thought, if you are still learning the ropes when it comes to networking, perhaps you could try create a simple chat application or similar for starters? Much of the networking theory would be the same, well at least in terms of clients connecting to servers etc. That way you can focus on the networking side of things, instead of trying to build a game and learn networking at the same time. I don't have any idea of your experience or anything, so sorry if it sounds like I'm trying to teach you to suck eggs!!  Smiley

nerb.
Offline sproingie

JGO Kernel


Medals: 201



« Reply #5 - Posted 2013-07-15 23:48:04 »

Any decent router should support NAT-PMP, which will open the ports invisibly.  Google searches suggests there's plenty of implementations out there for java.  You could also use UPnP but it's starting to wane in popularity for various good reasons.
Offline samcp12

Junior Member


Medals: 1



« Reply #6 - Posted 2013-07-16 02:39:09 »

Thanks guys, Yeah I created a small chat program I actually know a fair bit but was struggling in applying it to game development. I have as of now implemented what I was trying to do and it worked, I have been able to let a player type in a port and the player gets connected to the server at that port and have been able to send objects and handle them on the server. Thanks!
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.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!