Created
June 11, 2019 11:45
-
-
Save pinglunliao/de0541a9af9b6ba8ed1170ddf32b012c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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