EasyMocap/easymocap/socket/base_client.py

30 lines
852 B
Python
Raw Normal View History

'''
@ Date: 2021-05-25 13:39:07
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
2021-06-25 21:17:22 +08:00
@ LastEditTime: 2021-06-16 14:42:35
@ FilePath: /EasyMocap/easymocap/socket/base_client.py
'''
import socket
2021-06-25 21:17:22 +08:00
from .utils import encode_detect, encode_smpl
class BaseSocketClient:
def __init__(self, host, port) -> None:
if host == 'auto':
host = socket.gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
self.s = s
def send(self, data):
val = encode_detect(data)
self.s.send(bytes('{}\n'.format(len(val)), 'ascii'))
self.s.sendall(val)
2021-06-25 21:17:22 +08:00
def send_smpl(self, data):
val = encode_smpl(data)
self.s.send(bytes('{}\n'.format(len(val)), 'ascii'))
self.s.sendall(val)
def close(self):
self.s.close()