Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1781 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:, 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 Bitwise Duke »

Medals: 167
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
« 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  

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

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

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

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

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

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!