| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- # -*- coding:utf8 -*-
- #!/usr/bin/env python
- import threading
- import hashlib
- import socket
- import base64
- import time
- import json
- #创建一个客户端的socket对象
- client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- #设置服务端的ip地址
- host = "127.0.0.1"
- # host = "192.168.1.53"
- #设置端口
- port = 9999
- #连接服务端
- client.connect((host, port))
- data = {'client_id':'1001','at':25,'ah':65}
- #while循环是为了保证能持续进行对话
- # while True:
- # pass
- # 输入发送的消息
- # # sendmsg = input("请输入:")
- # sendmsg = json.dumps(data)
- # #如果客户端输入的是q,则停止对话并且退出程序
- # # if sendmsg=='q':
- # # break
- # sendmsg = sendmsg
- # #发送数据,以二进制的形式发送数据,所以需要进行编码
- # client.send(sendmsg.encode("utf-8"))
- # msg = client.recv(1024)
- #接收服务端返回的数据,需要解码
- # print(msg.decode("utf-8"))
- # time.sleep(5)
- #关闭客户端
- # client.close()
|