24 lines
506 B
Python
24 lines
506 B
Python
|
import socket
|
||
|
import json
|
||
|
|
||
|
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
|
|
||
|
server_address = ('localhost', 8080)
|
||
|
print(f'Connecting to {server_address}...')
|
||
|
client_socket.connect(server_address)
|
||
|
|
||
|
try:
|
||
|
data = {
|
||
|
'message': 'Hello from Python',
|
||
|
'value': 42,
|
||
|
'enabled': True
|
||
|
}
|
||
|
|
||
|
json_data = json.dumps(data)
|
||
|
|
||
|
print(f'Sending: {json_data}')
|
||
|
client_socket.sendall(json_data.encode())
|
||
|
|
||
|
finally:
|
||
|
print('Closing connection')
|
||
|
client_socket.close()
|