I have a socket server program:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Author:sele
import socket
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
when I run it in my terminal:
there get error:
sele-MacBook-Pro:test01 ldl$ ./tests02-server.py
Traceback (most recent call last):
File "./tests02-server.py", line 11, in
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
AttributeError: exit
why there get this error?
with
until 3.x. – jasonharper