java - Received string over socket does not compare in python -



java - Received string over socket does not compare in python -

i trying compare string received on socket in python send java. fails compare. if run simple if statement in idle, works. when seek receive string , compare it.

java code sending string:

string nummer = "1"; printwriter out = new printwriter(new bufferedwriter( new outputstreamwriter(socket.getoutputstream())), true); out.println(nummer);

python code:

while true: # found connection clientsocket,addr = serversocket.accept() print("got connection %s" % str(addr)) returnmsg = clientsocket.recv(1024) command = str(returnmsg.decode('utf-8')) print(command) if command == 1: time.sleep(1) print('open') time.sleep(1) if command == '0': time.sleep(1) print('close') time.sleep(1) if command != '1' , command != '0': print('something else') clientsocket.close() print('socket closed')

the output shown on python console follows:

got connection ('192.168.0.101', 50148) 1 else socket closed

it ends in lastly statement. tried comparing like:

if command == '1': if command == "1":

what should do, in java (android) have 3 buttons. 2 buttons send 1 or 0 (in string). other sends string more characters. string not important.

it ends in lastly statement. should not do. , not come in right statement. should print "open" when click button in android app.

any 1 knows how solve enters right statement , not come in last?

cheers.

you've got line feed on wire ought compare against "1\n" or .strip() it

java string sockets python-3.x compare

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -