使用Python進行socket通信

 //

import socket

def talk(data):
    """Send data to a Daemon, and return the response"""
    reply = ""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect(("127.0.0.1", 5678))
    except socket.error as e:
        print e.strerror
    else:
        s.sendall(data)
        reply = recv_all(s)
    s.close()
    return reply

發佈了102 篇原創文章 · 獲贊 8 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章