Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  ObjectInputStream for tcp/ip gaming, can message B arrive before message A?  (Read 2798 times)
0 Members and 1 Guest are viewing this topic.
Offline zappsweden

Junior Member




Java games rock!


« Posted 2007-02-18 15:38:18 »

I am making a game which has chat and has moves. Each with its separate port for communication. Here is how the object waits for incoming traffic

while (true) {
            
            Object o = oiStream.readObject();

                        if(o!=null)
                      {
                                blahblahblah = the code here
                     }


The code works but I am curious what happens if the client sends 2 messages and the second message arrive first? Is objectinputstream handling such things or do I need to ID tag the messages?
Offline sunsett

Senior Member




ribbit!


« Reply #1 - Posted 2007-02-18 15:45:14 »

Your oiStream references a single client, not multiple clients so there wouldn't be a problem, but depending on implementation you're likely blocking the second client from connecting or communicating while this is occurring.
Offline zappsweden

Junior Member




Java games rock!


« Reply #2 - Posted 2007-02-18 16:50:28 »

Your oiStream references a single client, not multiple clients so there wouldn't be a problem, but depending on implementation you're likely blocking the second client from connecting or communicating while this is occurring.

What second client (since I do not need one)?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sunsett

Senior Member




ribbit!


« Reply #3 - Posted 2007-02-18 17:01:01 »

oh...my mistake, I misread what you wrote.

TCP guarantees the order of delivery, so unless you have two threads that are trying to stream data at the same time you shouldn't run into any issues.

Something you might consider if the above is the case (here comes the advertising) is my networking API JGN (JavaGameNetworking) as it can handle multiple simultaneous streams coming from multiple clients.

http://javagamenetworking.dev.java.net
Offline zappsweden

Junior Member




Java games rock!


« Reply #4 - Posted 2007-02-18 17:05:22 »

oh...my mistake, I misread what you wrote.

TCP guarantees the order of delivery, so unless you have two threads that are trying to stream data at the same time you shouldn't run into any issues.

Something you might consider if the above is the case (here comes the advertising) is my networking API JGN (JavaGameNetworking) as it can handle multiple simultaneous streams coming from multiple clients.

http://javagamenetworking.dev.java.net

So, is the multiple streams a problem even if i use different port i.e different socket?
Offline sunsett

Senior Member




ribbit!


« Reply #5 - Posted 2007-02-18 20:12:48 »

No, but you've got to realize that OIS blocks so you'll have to have a thread for each stream that is going concurrently.  JGN resolves this by using non-blocking IO.
Offline zappsweden

Junior Member




Java games rock!


« Reply #6 - Posted 2007-04-25 22:06:05 »

I have one thread running for chat and one for other actions and those 2 have separate ports. Despite that, I have experienced crashes that seem to occur when using the chat.

If I have a chat and both players send simultaneously then it woudl not crash?
Meaning, it is probably that the 2 different threads interfer somehow despite on different ports?
I am going to buy a second computer soon so that I can easier provoce these crashes myself and get an answer.
Offline JAW

Senior Member


Medals: 2



« Reply #7 - Posted 2007-04-26 08:43:15 »

Each connected client will connect on an own socket. If each communication is in a thread, you cannot guarantee in which
order the clients send data. A TCP connection will guarantee:
- the right order / sequence of data
- nothing gets lost
- everything is correct, no data corruption

So each single connection is safe, but if you have multiple clients you need to handle them sequential or parallel.

-JAW
Offline zappsweden

Junior Member




Java games rock!


« Reply #8 - Posted 2007-04-29 00:38:55 »

I think I might have found the problem. Will be able to see later on when I buy a second computer. The 2 threads I have all add their results into one OrderThread in game that has vector storing up all stuff and performing it into the game. Since both threads access the same OrderThread some problem may occurr. I have put synchronized keyword on all the public methods in the OrderThread class now, so I will see if that solve it Smiley
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.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (55 views)
2014-07-14 18:02:53
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!