Reading data pushed to a TCP socket after it is closed

Posted on 2011-10-17
Last Modified: 2012-06-21
I have a C++ program ( which would be difficult to update) that  pushes a bunch of ascii data to the connected socket then calls exit(0) which also closes the socket.

I have been attempting to write a java client to the existing C++ server program.  When I reading the input from the socket using a stream using BufferedReader, I get a " Connection reset" instead of being able to read to the end of the data already pushed to the socket. Does anyone know a way to get Java to let me read all of data?
Question by:I_s
    LVL 86

    Expert Comment

    I'm confused. You want to 'translate' the C++ client into Java?
    LVL 67

    Accepted Solution

    Closing the TCP socket before all packets are acknowledged is rogue. TCP is a reliable protocol, and needs its packet to be acknowledged. As soon as the socket is closed, a FIN or RST is sent, and the connection has gone. There is no way to access the closed socket anymore for the application. There are, however, ways to monitor traffic, as packet capturing software (WireShark) does.

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Suggested Solutions

    Article by: SunnyDark
    This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now