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 (856)
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 3372 times)
0 Members and 1 Guest are viewing this topic.
Offline samcp12

Junior Devvie

Medals: 1

« Posted 2013-07-12 22: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: 382
Projects: 11
Exp: 4 years

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

« Reply #1 - Posted 2013-07-12 22:14:24 »

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

Offline Stranger
« Reply #2 - Posted 2013-07-13 06:16:47 »

You may want to look at the posts:

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

Junior Devvie

Medals: 1

« Reply #3 - Posted 2013-07-14 16: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 02: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

Offline sproingie

JGO Kernel

Medals: 202

« Reply #5 - Posted 2013-07-15 21: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 Devvie

Medals: 1

« Reply #6 - Posted 2013-07-16 00: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  

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

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

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

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

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

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

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

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

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

nelsongames (2600 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!