How to send data from device to remote server?

Java socket and memory issues: I am writing a client/server that need to send data and images.?

  • I am writing a program that needs to track where the server user's mouse is on the screen and send that information back to the client. I also need the client to be able to send an image to the server for display. What is the best way to do this? Currently I have implemented the image send using ObjectOutputStreams and ObjectInputStreams but I get a "java.lang.OutOfMemoryError: Java heap space" error after sending about 13 images. It points to the input stream as the cause of the error, but if I reinitialize the stream then I get a Stream Corrupted error. Is there a better way to do this or do I have the wrong idea as to what is causing the memory issue? Also, I am currently running both the send and receive data on the same socket and the Client and Server are each running on their own thread. Is this acceptable or would you suggest another implementation? Thanks for any help you can provide, I am completely new to threading and sockets.

  • Answer:

    Two abstract classes shape the architecture of the java.io package: InputStream and OutputStream. These interfaces define the key abstractions for I/O operations. Concrete implementations of InputStream and OutputStream provide access to different types of data sources such as disks and network connections. The java.io package also provides several filter streams that don't point to a specific data source and are meant to be stacked on top of other streams. These filter streams are at the heart of the java.io architecture. From a performance perspective, the most interesting filter streams are buffered streams. The leading cause of poor I/O performance is failing to buffer I/O operations. Hard disks are very good at reading and writing sizable chunks of data, but they are much less efficient when working with small blocks of data. To maximize I/O performance, you should batch read and write operations. This is exactly what buffered streams are designed for. Key Points * Reading and writing data in small chunks can be very slow. * Using BufferedInputStream and BufferedOutputStream to batch requests improves performance. * In some situations, you can use custom buffering techniques to maximize performance. Forth visit http://java.sun.com/docs/books/performance/1st_edition/html/JPIOPerformance.fm.html hope this will solve you issues Cheers:)

C H at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.