-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
40 lines (34 loc) · 1.13 KB
/
client.py
File metadata and controls
40 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Программа клиента
import sys
import time
from socket import *
from jim.utils import encode, decode
from jim.config import *
account_name = "User"
message = {
ACTION: PRESENCE,
TIME: time.time(),
USER: {
ACCOUNT_NAME: account_name
}
}
if __name__ == '__main__':
s = socket(AF_INET, SOCK_STREAM) # Создает сокет TCP
# Получаем аргументы скрипта
try:
addr = sys.argv[1]
except IndexError:
addr = 'localhost'
try:
port = int(sys.argv[2])
except IndexError:
port = 7777
except ValueError:
print('Порт должен быть целым числом')
sys.exit(0)
s.connect((addr, port)) # Соединиться с сервером
s.send(encode(message)) # Отправить запрос серверу
print("Отправлено сообщение серверу")
data = s.recv(1024) # Принять не более 1024 байтов данных
s.close()
print("Получен ответ от сервера:", data)