python tcp client script
I want to send the message "How are you!" continuously to the server. the server would respond either "I am fine" or "I am not okay"
Code: Select all
#!/usr/bin/env python import socket TCP_IP = '192.168.0.2' TCP_PORT = 5006 BUFFER_SIZE = 1024 MESSAGE = "How are you!" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send(MESSAGE) data = s.recv(BUFFER_SIZE) s.close() print ("received data:", data)
if the server responds " I am fine " do nothing but if the server responds "I am not okay" then print the message " I will take care of you"
How to make python client script for the above purpose?