- #1
ShaddollDa9u
- 18
- 0
Hi everyone, I have just started learning sockets in python and I have made the following code:
so obviously, when I connect to that server and send "blabla", I should normally get "works" as an answer, but somehow, I always get the "nope" like if the if condition was not respected. Can you please help me to solve this ??
PS : I use python 3.6 in Linux.
Python:
import socket
HOST = ''
PORT = 8888
def main():
while 1:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
while 1:
data = conn.recv(1024)
if ( data == "blabla"):
conn.send("works")
else:
conn.send("nope")
conn.close()
s.close()
if __name__ == '__main__':
main()
so obviously, when I connect to that server and send "blabla", I should normally get "works" as an answer, but somehow, I always get the "nope" like if the if condition was not respected. Can you please help me to solve this ??
PS : I use python 3.6 in Linux.