• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Debug Output Streams

 
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello how to debug output streams in Java?

Im using currently eclipse and have made some breakpoints.
When i click on output1 which is my DataOutputStream I don't see what the client actually receive.



Is "written" what actually gets out?

The method I use is writeUTF()
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't expect an OutputStream object to contain a copy of everything ever sent through the stream. In fact most OutputStream objects are going to contain at best buffered data which hasn't been sent yet. I'd say that you're on the wrong track here.
 
Kevin Olome
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, thanks for the answer.

Maybe i have something different wrong.

The thing is:
on the first loop everything works perfect.
After the second loop the client waits for an input although im sure the server is sending for the waiting input.

Thats a bit strange and I coudln't figure out why it wont work.

Here is the code (if it helps)
GameThread:


Server:


Client:


I am really helpless.
It's just a rock scissors paper game and I wasted about 30 hours trying to figure out whats wrong.
First I thought i can make an even harder version with a stop condition by a user but soon a figured out that this is a bit far to high for my skills.

So now i tryed to stop the rock paper scissors game after someone won atleast 2 games and win_player1 != win_player2

The problem is:
The first time I run it it works perfect.
The second time the client waits for readUTF from the Server.
Now i checked this condition about 100000 times and can't find any error.
(by the server and by the client)

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Olome wrote:The problem is:
The first time I run it it works perfect.
The second time the client waits for readUTF from the Server.



I don't understand this. I think that's because I don't understand what the "it" is which you said you ran twice. Is "it" just the server? Or maybe the server and both clients? Perhaps you didn't restart one of the clients and so it's waiting for something which will never come? In other words, it would help if you told us what you did.
 
Kevin Olome
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean with it:
I run the server, then the 2 clients.
Can play exactly one round (player1 can choose what he wants, player2 can choose what he wants) then the server responds accordingly.

After that player 1 and player 2 can make again their inputs.
Sever get the input.
Server calculates the input.
Client don't receive the input (readUTF())

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to say I find your server code very strange. You start out by deciding whether the game is over, before you even read anything from either of the clients. And you send several pieces of data to the clients in a particular order, but the clients seem to read those pieces of data in a different order, or perhaps they don't read all of them.

(The fact that the client code tells you what "player 2" did even when it doesn't know who player 2 actually is, that's probably just a confused way of saying "the other player".)

I suspect you don't have a clear description of the communication protocol between the server and the client; you should write that down first and then write code which actually implements it.
 
Kevin Olome
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is how the application is receiving and sending from the client and the server.





I checked the code multiple times and it does this just as expected.

Im wondering because how can it be that the application can run one time perfect. and the second time starts to freeze (because the client cant get the output (writeUTF) from the server.)

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this topic is too advanced for Beginning Java; I'm moving it to General.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately by splitting your description of the data transfers into "Sending" and "Receiving" you have made the description much less useful. A transmission protocol should specify what is sent by X in response to some data received from Y. That way you can tell whether things are happening in the correct order.
 
Kevin Olome
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see.
So I should have written what is send by client1 and what is send by the server or am I getting it wrong?
Also I have just made a simpler version of the game which just cancels after 1 game round and this works perfect.

But anyhow i am interested in how Output and Input streams are really working, cause I think maybe i understood it completly wrong.

When for example the server have an outputstream and says writeUTF().
Is this outputstream the whole time there for the client and when the client says readUTF() he can receive it.
OR is the outputstream only in the second the server sends it there so the client have to check like every millisecond if the server sends something to him?

Kind regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic