To learn Python Network programming, I wrote two small programs on the server and the client according to the book, and found that an error was reported:
Traceback (most recent call last):
File “./tsTserv.py”, line 20, in
data = tcpCliSock.recv(BUFSIZ)
File “/usr/lib/python2.6/socket.py”, line 165, in _dummy
raise error(EBADF, ‘Bad file descriptor’)
socket.error: [Errno 9] Bad file descriptor
The source code of the server side is as follows:
while True:
print 'waiting for connection...'
tcpCliSock,addr = tcpSerSock.accept()
print '...connected from:',addr
while True:
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
tcpCliSock.send('[%s] %s' %(ctime(),data))
tcpCliSock.close()
tcpSerSock.close()
Solution:
tcpCliSock.close() is placed in the second while loop, causing tcpCliSock to be closed after receiving data once, and this statement should be placed in the outer loop
Read More:
- [Solved] JDK Install Error /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
- Maven plugin development report error- plugin:3.2 :descriptor fai
- [Solved] maven Error: Failed to read artifact descriptor for org.
- [Solved] com.highgo.jdbc.util.PSQLException:bad value for long
- Java.sql.sqlexception: unable to read more data from socket
- [Solved] Windows Redis Error: Could not create server TCP listening socket 127.0.0.1:6379: bind…
- Using Post no Body Error: socket hang up [How to Solve]
- [Solved] socket failed: EPERM (Operation not permitted)
- [Solved] Springboot project introduces Font library error: java.awt.fontformatexception: bad table, tag = XXXXXX
- java.net.SocketException: software caused connection abort: socket write error resolution (selenium)
- [Tomcat] Unrecognized Windows Sockets error: 10106: Socket creation failed
- [Solved] Jedis connect and operate Redis error: Failed to create socket和connect timed out
- Redis Startup Error: Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
- [Solved] canal Startup Error: error while reading from client socket java.io.IOException: Received error packet:
- [Solved] Redis Error: Error condition on socket for SYNC: No route to host
- [Solved] Kafka in Windows error:java. nio. file. Filesystemexception: this file is in use by another program and cannot be accessed by the process
- [Solved] JAVA Python Error: Cannot create PyString with non-byte value
- JAVA: Random access file is always garbled
- Multipartfiletofileutils (multipartfile to file)
- How to Download File via Response (Example Code)