I want to receive and send data in ASCII how can I do? (Have the code)
I use my program connect to server (the server is .exe file) after I connect in ms-dos mode I want to send the command from client to server but nothing is happen such as I want to send MOVE 50 it means move 50cm nothing is back(may be because I haven't convert it to ASCII first) How can I change mycode to read and wrtie ASCII code?
publicclass proxy_server{
/** Creates a new instance of proxy_server */
publicstaticvoid main(String args[])throws IOException{
Socket sock=null;
PrintWriter out=null;
BufferedReader in=null;
sock =new Socket("localhost", 3000);
out=new PrintWriter(sock.getOutputStream(),true);
in=new BufferedReader(new InputStreamReader(sock.getInputStream()));
BufferedReader stdIn =new BufferedReader(new InputStreamReader(System.in));
String userInput;
while(( stdIn.readLine()!=null)){
userInput=stdIn.readLine();
out.println(userInput);
System.out.println("echo"+in.readLine());
}
out.close();
in.close();
stdIn.close();
sock.close();
}
}
[1943 byte] By [
676206a] at [2007-10-3 11:32:21]

> Blank lines aren't a reason to exit the loop
The stdin input often fails on null check, so we usually should use a blank-line-check as an exit condition.
Try this:
import java.io.*;
public class Stdin{
public static void main(String[] args) throws Exception{
String line = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while ((line = br.readLine()) != null){
System.out.println("READ: " + line);
}
System.out.println("exitted the loop");
}
}
hiwaa at 2007-7-15 13:59:11 >

> > Blank lines aren't a reason to exit the loop
> The stdin input often fails on null check, so we
> usually should use a blank-line-check as an exit
> condition.
Why? A null and a blank line aren't the same thing. A blank line might be perfectly valid data. Indeed it is in HTTP for example. If browsers behaved like this you wouldn't be able to read this post.
ejpa at 2007-7-15 13:59:11 >

> we usually should use a blank-line-check as an exit condition.
Certainy not 'usually'. See below.
> I was just talking about a primitive stdin input on
> console.
But nobody else was, especially the OP.
> Simple null check on readLine while loop often causes
> confusion among Java newbies becuase they can't exit
> the program.
If and only if you define your operating instructions so that pressing ENTER is the way to exit the program, you would include the blank line check. Not otherwise, and certainly not 'usually'.
Otherwise they can always type Ctrl/Z or Ctrl/D to exit the program. And that's the correct way to clear up the confusion. Terminating the loop on a blank line just adds to the confusion
ejpa at 2007-7-15 13:59:11 >

I thought it was rather obvious that I was talking about a specific/particular and limited context which OP's stdin code might typically represent. Small example codes for beginners often could use the [Enter] key effectively as an exit from console-input loop. That's so mediocre a topic, I think.
In a broader and more general context, I know top-ranked gurus on the forum like ejp are always right. I always learn a lot from them.
hiwaa at 2007-7-15 13:59:11 >

im using same sort of code
and i can NEVER get out of that **** while loop
how are u ment to properly check to see if the data stream has ended not shut down but just finished sending its current packet
im sending html sorta packets so cant check for /r/n n stuff
this != null seams to do FUUUUK all sure as *** dont exit the loop