I've written a Java TCP socket service and this service is used by a golang client.
Things get weird when the server socket response gets parsed on the golang side.
Specifically, this Java server code:
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(output));
bw.append('Y');
bw.append('E');
bw.append('S');
bw.append('
');
bw.flush();
And this golang client code:
extendTimoutFor(client.conn)
rspMsg, fault := bufio.NewReader(client.conn).ReadString('
')
if fault != nil {
return UNKNOWN, fmt.Errorf("Ers reading response: %v", fault)
}
retStr := strings.TrimRight(rspMsg, "
")
if retStr == YES {
return YES, nil
}
if retStr == NO {
return NO, nil
}
if retStr == FAIL {
return FAIL, nil
}
return UNKNOWN, fmt.Errorf("Ers parsing msg [%s]: %v", rspMsg, fault)
Produce this result in the client:
[UNDO|test|]: Ers parsing msg [YES
]: <nil>
My problem with the result is that the client doesn't recognize retStr as a valid response. Since rspMsg is what we expect (i.e. 'YES ') then if we're in the UNKNOWN block it means that something went wrong during this line: retStr := strings.TrimRight(rspMsg, " ")?
My specific questions are:
- Since there are nil errors shouldn't ' ' and (any characters following it) have been stripped leaving us with "YES"?
- Am I missing some quirk on the Java side? I've recreated the client using Java and the output is what I expect.