You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import socket
host_ip, server_port = "127.0.0.1", 9999 data = " Hello how are you?\n"
# Initialize a TCP client socket using SOCK_STREAM tcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: # Establish connection to TCP server and exchange data tcp_client.connect((host_ip, server_port)) tcp_client.sendall(data.encode())
# Read data from the TCP server and close the connection received = tcp_client.recv(1024) finally: tcp_client.close()
print("Bytes Sent: {}".format(data)) print("Bytes Received: {}".format(received.decode()))
|