[原创]python消息办事器改进,哄骗TCP通信

    添加时间:2013-5-23 点击量:

    server.py



    Writen by Hymenz
    
    import socket
    import thread
    import re
    s
    =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    ip
    =raw_input(Input the IP address you want to receive message:
    pt
    =raw_input(Input the port you want to listen:
    s.bind((ip,int(pt)))
    s.listen(
    1
    conn,addr
    =s.accept()
    while 1:
    print [%s:%d] send a message to me: %s%(addr[0],addr[1],conn.recv(1024))
    conn.sendall(
    I received a message [+addr[0]+:+str(addr[1])+]
    s.close()


    client.py



    Written by Hymenz
    
    import socket
    s
    =socket.socket()
    ip
    =raw_input(Input the Server\s IPv4 address:
    pt
    =raw_input(Input the Server\s port:

    s.connect((ip,int(pt)))
    while 1:
    sms
    =raw_input(Input the message you want to send:
    s.sendall(sms)
    print I received a reply:+s.recv(1024
    s.close()


    我们永远不要期待别人的拯救,只有自己才能升华自己。自己已准备好了多少容量,方能吸引对等的人与我们相遇,否则再美好的人出现、再动人的事情降临身边,我们也没有能量去理解与珍惜,终将擦肩而过。—— 姚谦《品味》
    分享到: