Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

i have a server client communication using java server sockets. The following few code snippets are to give u a basic overview of the technology i am using, its not the whole code.

     connectionSocket = serverSocket.accept();

     outputStream = new ObjectOutputStream(conectionSocket.getOutputStream() );
     outputStream.flush(); // flush output buffer to send header information

     receivedMessage = ( String ) inputStream.readObject();

  // set up input stream for objects
  inputStream = new ObjectInputStream( connectionSocket.getInputStream() );



     // send message to client
     private void sendData( String message ){
           try // send object to client
          {
           outputStream.writeObject(  message );
           outputStream.flush(); // flush output to client

           } // end try
           catch ( IOException ioException ) 
           {
           System.out.println("\n Server: Error writing object");
           } // end catch
      } // end method sendData

Client and server exchanging String messages ( which are several joined strings plus a Base64 encoded picture ).

Everything works pretty well if i am using pictrues with a size of 300KB. If i use pictures with a size of 1,5MB i am freuqently getting the following error:

Blockquote java.net.SocketException: Connection reset at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.net.SocketInputStream.read(Unknown Source) at java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source) at java.io.ObjectInputStream$BlockDataInputStream.peek(Unknown Source) at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at ServerAccessPC.processConnection(ServerAccessPC.java:116) at ServerAccessPC.runClient(ServerAccessPC.java:52) at ServerAccessPC.setDataOnServer(ServerAccessPC.java:338) at JTabbedPaneFrame$3.actionPerformed(JTabbedPaneFrame.java:192) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.AbstractButton.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

So my question,

is there a maximum size of a String that can be transferred via sockets in Java? What else could cause the error when the size of the transferred Strings is getting to big?

Thanks for any help

share|improve this question
    
Are the lines receivedMessage = ( String ) inputStream.readObject(); and inputStream = new ObjectInputStream( connectionSocket.getInputStream() ); in the same order in your question as they are in your code? – fdsa May 13 at 15:20
    
yes. The whole client - server communication is based on the deitl book, java 9 how to programm, so i don´t think there is anything wrong with it – Arnold May 13 at 15:33
    
Where is inputStream initialized the first time? – fdsa May 13 at 15:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.