Here's what I'm trying to do
1. Write a TCP Client that will connect to 127.0.0.1 on port 9990.
2. send "Hello, World" to the server.
3. get the response, and print it out.
Here is my code:
![[Image: cywbGmw.png]](https://i.imgur.com/cywbGmw.png)
1. Write a TCP Client that will connect to 127.0.0.1 on port 9990.
2. send "Hello, World" to the server.
3. get the response, and print it out.
Here is my code:
![[Image: cywbGmw.png]](https://i.imgur.com/cywbGmw.png)
Code
from time import sleep
import socket
c_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c_socket.connect(('127.0.0.1', 9990))
c_socket.send('hello, world')
test = c_socket.recv(1024)
print(test)
s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s_socket.bind(("127.0.0.1", 9990))
s_socket.listen(10)
while True:
connection, address = s_socket.accept()
test = connection.recv(1024)
if len(test) > 0:
print(test)
connection.close()
break
s_socket.close()
sleep(0.05)


![[Image: 4YPLYme.gif]](https://i.imgur.com/4YPLYme.gif)