• Post Reply Bookmark Topic Watch Topic
  • New Topic

unbuffered input  RSS feed

 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java application that plays chess. I'm trying to interface with various chess servers which require the program to simply read lines of input and write lines of output. It should be simple and works fine when I test things by hand however I believe I'm running into buffering issues as the program sits there waiting for input and the server states it's already sent a command. I've also heard that people have had buffering issues when using other languages ie C etc.

Is there a simple way of read a line of input as a string with no buffering?

I tried the Console method but sadly there isn't a console when the program is trying to connect to the server.

Help!
 
Stephan van Hulst
Saloon Keeper
Posts: 6984
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mich, maybe you can show us what code you have now, that's causing you problems.
 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Existing code:

It just splits the input line up into words and feeds the words back one at a time. When it runs out of words it reads a new line. I works perfectly when I run it from the command line but when interfacing to winboard (a program that runs chess engines against each other) it works for a short while and then stops to wait for input. Unfortunately the other side thinks it's passed the input so it sits there to. On the web I've seen issues regards buffering (in the C language) and so I'm trying to see if I have the same issue here.
 
Stephan van Hulst
Saloon Keeper
Posts: 6984
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wild guess: You use a new BufferedReader on every invocation of the method, reading a big chunk of input every time you read a new line, which will throw away available input after the method is done.

Don't take this the wrong way, but I'm not looking into this any further before you get rid of the silent catch.

Even if you don't handle an exception, you should *always* log it some way. You should also catch the most specific exception possible. *Never* catch Throwable or Exception.

You should also use proper coding conventions. Your variables should start with a lower case letter. You should also put the braces of an array declaration with the element type, not with the variable name. The braces indicate a type after all.
 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your code sample, I've added that in (and added the stack traces etc on IOExceptions). Your points are all very valid but I'll add it's probably worth always using curly braces after if statements etc rather than relying on indentation as it's all too easy to just add more code at the correct indentation and then wonder why it runs no matter what the condition. Your suggestions have fixed my initial problem though the servers aren't communicating properly with my chess engine yet but hopefully I'll wear them down.

Again thank you for your help.
 
Stephan van Hulst
Saloon Keeper
Posts: 6984
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are they not communicating properly? Can you post an SSCCE?
 
Mich Robinson
Ranch Hand
Posts: 260
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem isn't with your code but with the communication protocol. I've never used it before and the documentation (and error codes) are a little scant. Impossible to give a SSCCE in this case but I'll speak with the chess server developers to see what I'm doing wrong. If I can narrow it down and need help then I'll post. Thanks for your help.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!