Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  newbie asking about socketing programming  (Read 1178 times)
0 Members and 1 Guest are viewing this topic.
Offline locuschan

Junior Newbie





« Posted 2010-06-02 20:28:55 »

I have some question about socket programming, clarify me if I have any misunderstanding
Say if I want to build a multi-client IM like this one:
http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html, the Example 2: Multithreaded Server Example
What I’m able to do is, every client can send a message to the server. And the server receives those messages sent by all clients. Every client receives his OWN response reply by the server.
But this is not IM means. IM means client can talk to client. But with my code, that’s only every client talk to the server separately. I would like to know how to write the code such that client can pass a message to the server. The server then broadcast that message to all clients to let them see.

As my code, everything starts from the clients’ action. But if I want to notify other client (recipient) that a message appears, it somehow needs to trigger by the server.
What is the proper way to make a communication between clients?

This may be naïve for you, or I didn’t explain the question well. Anyway, any advices are welcome.
thank you.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2010-06-02 22:25:05 »

In a client-server architecture, each client can only talk to the server. To send an IM from client to client, client1 sends a message to the server, which sends a message to client2, telling them, "this is from client1". In your app, you need to implement server logic when a message is received from a client. You can forward that to another client, respond with the same message, send it to all clients, send new messages to any of the clients, etc.

Offline locuschan

Junior Newbie





« Reply #2 - Posted 2010-06-03 20:31:45 »

thanks Nate, you clarify my concept.
another question.

if i want to build a multiplayer game, part of the screen there is a text field for players to chat
then should i use 2 thread? one for chating(e.g. BufferedReader/PrintWriter), another for players' movement (e.g. ObjectInputStream/ObjectOutputStream)
since if I integrate them in a single thread,  the run method will block either by BufferedReader.readLine() or ObjectInputStream.readObject()
thanks Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ddyer

Senior Member


Medals: 5



« Reply #3 - Posted 2010-06-03 21:17:22 »

You'll have lots of different types of messages flowing back and forth, so there's no reason
why chat messages shouldn't be just another type.  No need to use a separate stream.

You game logic should never block for I/O.  I/O will stall unpredictably and you definitely
do not want that to affect rest of the game.   Outgoing messages should be queued
and incoming messages should be received, blessed, and queued for your game engine
to eat.
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.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (26 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!