python 脚本模拟tcp和udp客户端

复制代码
import socket
import time

# client
#tcp客户端
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#udp客户端
#client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.connect(('192.168.0.123', 7007))
print("connect localhost 7007 ...")

while True:
    #sendbuf = "{\"a\":8,\"b\":9}'\0'"
    sendbuf = "{\"a\":8,\"b\":9}'\0'"
    print("send :", sendbuf)
    client.send(sendbuf.encode('utf-8'))
    if not sendbuf or sendbuf == 'exit':
        break
    time.sleep(1)

client.close()
print('Connection was closed...')
复制代码

 

posted on   uestc2007  阅读(78)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
历史上的今天:
2019-10-24 (八)DVWA之SQL Injection--SQLMap&Burp测试(Medium)

导航

< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示