generated from justuser-31/code_projects_template
Решения на первый блок
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import socket
|
||||
|
||||
# Create a socket object
|
||||
s = socket.socket()
|
||||
port = 12345
|
||||
s.connect(('127.0.0.1', port))
|
||||
|
||||
data = '''{
|
||||
"name": "Иван Иванов",
|
||||
"age": 25,
|
||||
"city": "Москва"
|
||||
}'''
|
||||
|
||||
# Send data
|
||||
s.send(data.encode())
|
||||
# Receive data
|
||||
print(f'STATUS: {s.recv(1024).decode()}')
|
||||
|
||||
s.close()
|
||||
@@ -0,0 +1,28 @@
|
||||
import socket
|
||||
from json import loads
|
||||
|
||||
# Create a socket object
|
||||
s = socket.socket()
|
||||
port = 12345
|
||||
s.bind(('127.0.0.1', port))
|
||||
print ("socket binded to %s" %(port))
|
||||
|
||||
# Put the socket into listening mode
|
||||
s.listen(5)
|
||||
|
||||
while True:
|
||||
# Establish connection with client.
|
||||
c, addr = s.accept()
|
||||
print ('Got connection from', addr )
|
||||
|
||||
raw_data = c.recv(1024).decode()
|
||||
data = loads(raw_data)
|
||||
print("\nParsed data:")
|
||||
for i in data:
|
||||
print(f'{i} - {data[i]}')
|
||||
print()
|
||||
|
||||
c.send('OK'.encode())
|
||||
|
||||
# Close the connection with the client
|
||||
c.close()
|
||||
Reference in New Issue
Block a user