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
Related Q & A:
- How can I get through a proxy server?Best solution by Super User
- How to store documents/images/video on a different server in sharepoint 2010?Best solution by SharePoint
- How cookies are handled if you use a proxy between a client and server in HTTP?Best solution by Stack Overflow
- How do I connect to a SQL Server database?Best solution by Stack Overflow
- I need tips for writing a song.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.