Python Forum
TCP/IP client script help
Thread Rating:
  • 4 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCP/IP client script help
#1
Client script
Here's simple code to send and receive data by TCP in Python:
#!/usr/bin/env python

import socket

TCP_IP = '192.168.0.12'
TCP_PORT = 5004
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)
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"

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?
Reply


Messages In This Thread
TCP/IP client script help - by Rehan11 - Jan-12-2019, 12:52 PM
RE: TCP/IP client script help - by nilamo - Jan-14-2019, 07:44 PM
RE: TCP/IP client script help - by Rehan11 - Jan-15-2019, 06:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python script multi client server sonra 1 2,429 Mar-24-2020, 03:49 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020