Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created June 11, 2019 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/de0541a9af9b6ba8ed1170ddf32b012c to your computer and use it in GitHub Desktop.
Save pinglunliao/de0541a9af9b6ba8ed1170ddf32b012c to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import socket
s = socket.socket()
host = socket.gethostname() # 取得目前機器名稱
print(host)
port = 12345 # 程式的 port number
s.bind((host, port))
s.listen(5) # 等待 client 連線
while True:
c, addr = s.accept() # 與 client 建立連線
print('有連線從', addr)
msg = '您好!!!'
c.send( msg.encode('utf-8') ) # 以 utf-8 傳送字串
c.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment