1

I'm writing a socket server in python. It needs to send acknowledgement to the client module. Quote from the protocol description:

"[...]server should determine if it would accept data from this module. If yes server will reply to module 01 if not 00."

I implemented this in python as:

connection.send('01')

It isn't working, so I checked the java implementation of the server:

        byte[] answer = {
            0x01};
        out.write(answer);
        out.flush();

I wonder whether it's the same or not? The System.out.write(answer); doesn't seem to output a thing to the console.

1 Answer 1

5

You're sending two bytes, 0x30 followed by 0x31, whereas the Java code is sending just one byte, 0x01.

Try the following instead:

connection.send('\x01')

In case you're wondering where the 0x30 and 0x31 came from, they are ASCII codes for the characters '0' and '1'.

3
  • connection.send('\x01') maybe?
    – ulidtko
    Commented May 16, 2012 at 12:17
  • @ulidtko: Same thing (the two are exactly equivalent).
    – NPE
    Commented May 16, 2012 at 12:18
  • @aix, but '\x01' is much more closer to Java's byte[] {0x01}.
    – ulidtko
    Commented May 16, 2012 at 12:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.