1 Star 0 Fork 0

小生/AnimalDetectyolo

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcpserver.py 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
xiaosheng 提交于 2022-05-05 22:53 +08:00 . first commit
#!usr/bin/env python
# coding:utf-8
"""
@File :tcpserver.py
@Author:小生
@date : 2022-05-04 21:24
"""
import socket
import time
def server():
'''
服务端程序
'''
# 填写云主机的内网IP 不是公网IP
server_ip = '127.0.0.1' # 绑定内网IP
server_port = 5000 # 监听端口
# 1.先调用socket.socket()创建socket套接字
# socket.AF_INET 表示ipv4
# SOCK_STREAM 表示使用tcp链接
# 2.bind()绑定监听的IP和端口
# 3.listen()开始监听
# 4.accept()接受客户端发来的消息
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((server_ip, server_port))
s.listen()
print("ready to connect:")
while True:
conn, client_ip = s.accept()
with conn:
print('Connected by', client_ip)
while True:
client_data = conn.recv(1024)
print("client:", client_data.decode())
if not client_data:
print('client data is null')
break
response_data = "hello client"+str(time.time())
response_data_byte = bytes(
response_data, encoding='utf-8')
conn.send(response_data_byte)
server()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/nirenxing/animal-detectyolo.git
git@gitee.com:nirenxing/animal-detectyolo.git
nirenxing
animal-detectyolo
AnimalDetectyolo
master

搜索帮助