BZ易风

导航

 
 1 import socket
 2 
 3 
 4 def main():
 5     # 1.常见套接字对象
 6     tcp_server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
 7 
 8     # 连接服务器
 9     server_ip = input("请输入服务器ip:")
10     server_port = int(input("请输入端口号:"))
11     server_addr = (server_ip,server_port)
12     tcp_server_socket.connect(server_addr)
13 
14     # 发送信息
15     send_msg = input("请输入发送内容:")
16     tcp_server_socket.send(send_msg.encode("gbk"))
17 
18     # 关闭套接字
19     tcp_server_socket.close()

 

posted on 2019-08-19 11:03  BZ易风  阅读(132)  评论(0编辑  收藏  举报