Python Socket
阿新 • • 發佈:2017-12-05
mage div copy serve 127.0.0.1 too client alt 2-2
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import socket
ip_port = (‘127.0.0.1‘,6000)
sk = socket.socket()
sk.bind(ip_port)
sk.listen(5)
while True:
print(‘server waiting...‘)
conn,addr = sk.accept()
client_data = str(conn.recv(1024),encoding=‘utf-8‘)
print(client_data)
conn.sendall(‘Hi ‘)
conn.close()
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import socket
sk = socket.socket()
sk.connect((‘127.0.0.1‘,6000))
sk.sendall(bytes(‘hello‘,encoding=‘utf-8‘))
server_reply = str(sk.recv(1024),encoding=‘utf-8‘)
print(server_reply)
sk.close()
Python Socket