Home > Default > Print a null character

Print a null character

November 30Hits:0
Okay, so I open a socket and connect to a networked machine that accepts strings as commands. Commands are terminated by the null character '\0'. I know this works as I've done it in Python with no problems. Right now all I'm trying to do is write an ascii char "0" followed by a null. My machine isn't responding and I'm pretty sure its because Java is ignoring my '\0' and just writing the characters preceding it.
   public void connect() throws IOException{
        System.out.println("Trying to connect...\n");
        //connect to roobt
        Socket outsock = new Socket("", 15223);
        Socket insock = new Socket("",15224);
        //setup reading/writing.
        PrintWriter out = new PrintWriter(outsock.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(insock.getInputStream()));
        String r = in.readLine();
        System.out.println("Received: " + r + "\n");
        //inform robot that connection is closing
        //close sockets
    }Am I wrong? Is there a way to force the null character to be written?
And as an aside, is there a way to read lines terminated by a null as opposed to a newline \n or carriage return \r? I can modify the code on the machine to respond with lines terminated by \n's, but I'd rather not have to redo it all. I wrote the code for my machine to function with a Python socket script, and now I'm attempting to rewrite this into Java.


Use the null character as the delimiter.Okay, I see how this could be useful, except I don't have a string yet. A have a BuffereReader that I need to make into a string. Once its a string, then I could use the scanner. Right? So, I still have a problem.

Read other 8 answers


Related Articles

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.442 s.