I made in python a little server that listen on port 4444,when i connect with telnet it's all fine,i can send message and the server display the message correctly. I have only one problem: When i try to "parse" the telnet message,I can't do it correctly. Infact with the If output=="screenshot" i want if the message i sent is "screenshot",the server print on the console a message. This don't work. This is my source,i am new to Python and network programming. Thanks in advance ** EVEN IF I USE == IN THE IF STATEMENT IS THE SAME** Coogle
SOURCE
import head
print("SockShot Server Starting\n")
sock=head.Server("localhost",4444)
print("Server STARTED")
while True:
sock.s.listen(1)
conn,addr=sock.s.accept()
print("Connessione stabilita con : {0}:{1} \n".format(addr[0],str(addr[1])))
conn.send("Benvenuto \n".encode())
sock.ricevi(conn)
HEAD.py
import socket
import sys
class Server:
server=""
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def __init__(self,server,porta):
self.server=server
try:
self.s.bind((server,porta))
print("Server binding complete \n")
except:
print("Binding server incomplete")
sys.exit(2)
def ricevi(self,socket):
result=socket.recv(1024)
while len(result)>0:
try:
print(result.decode())
result=socket.recv(1024)
self._check(str(result.decode()))
except:
print("Connection CLOSED BY CLIENT \n")
break;
socket.close()
def _check(self,output):
if output is "screenshot":
print("Screenshot ESEGUITO \n")
else:
print(output)
print(output)withprint("'%s'"%output)to see if there is any invisible char ?len(output)? should be equal to 10 . Also I see that you are doingresult=socket.recv(1024)twice, before the loop and in the loop. Are you sure that your method_checkis called ? because there is alsoprint(result.decode())that print the resut.