Skip to content

Broken pipe error executing a Python client script #1

Closed
@jicahoo

Description

@jicahoo

Python test script:

#py27
import socket
import time

if __name__ == '__main__':
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('127.0.0.1', 9999))
    for i in range(10):
        msg = "abcdefgh-%s" % i 
        print "send %s" % msg 
        s.sendall(msg)
        r = s.recv(1024)
        print r
        #print msg == r
        #assert msg == r
    # shutdown gracefully, or server won't recieive EOF which will lead to 
    # exception.
    s.shutdown(socket.SHUT_RDWR)
    s.close()

Reproduce steps/env:

  1. The buffer in server is only 8.
  2. Send message whose size is bigger than 8 every time (s.sendall()

Got error in stdout:

Exception in thread "main" java.io.IOException: Broken pipe
	at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
	at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
	at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
	at sun.nio.ch.IOUtil.write(IOUtil.java:65)
	at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
	at com.hello.echo.server.RealNioEchoServer.server(RealNioEchoServer.java:86)
	at com.hello.echo.server.RealNioEchoServer.main(RealNioEchoServer.java:99)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions