Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Broken pipe Exception.. please help

843790Jan 13 2009 — edited Jan 13 2009
I am trying to connect a number of clients to this server, and I keep on getting Broken pipe error. I have tried various combinations, but to no avail. Can someone please take a look at it and help me with this code.
public class HostCommunication extends Thread{
	private ServerSocketChannel serverSocket;
	private SocketChannel clientSocket;
	private ObjectInputStream objInputStream;
	private ObjectOutputStream objOutputStream;

	public HostCommunication(ServerSocketChannel serverSocket){
		this.serverSocket = serverSocket;
		try {
			this.serverSocket.socket().setSoTimeout(0);
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void run(){
		System.out.println("IN HOST COMM");
		try{	
			
			while(true){
				clientSocket = this.serverSocket.accept();
				clientSocket.socket().setKeepAlive(true);
				clientSocket.socket().setSoTimeout(0);
				
				System.out.println("IS ALIVE: "+clientSocket.socket().getKeepAlive());
				//clientSocket.socket().setKeepAlive(true);
				
				objInputStream = new ObjectInputStream(clientSocket.socket().getInputStream());
				objOutputStream = new ObjectOutputStream(clientSocket.socket().getOutputStream());
				Object incoming = objInputStream.readObject();

				if(incoming instanceof String){
					String chunkName = (String)incoming;
					if(DataServer.cacheTable.get(chunkName) != null){
						System.out.println();
						System.out.println("Found cache for " + chunkName);
						MappedByteBuffer buff = DataServer.cacheTable.get(chunkName);
						buff.rewind();
						Integer size = buff.capacity();
						objOutputStream.writeUnshared("buffer");
						objOutputStream.writeUnshared(size);
						buff.rewind();
						clientSocket.write(buff); //**** This is where I get the ERROR
						clientSocket.close();
					}else{
						System.out.println("Cannot find cache for " + chunkName);
					}
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
The stack trace that it generates is as follows:
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
at sun.nio.ch.IOUtil.write(IOUtil.java:60)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
at HostCommunication.run(HostCommunication.java:52)


Any help would be really appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2009
Added on Jan 13 2009
4 comments
396 views