user462982
user462982

Reputation: 1645

Java: How to monitor a plain socket connection (and forward results to the internal logger)

I am spoiled by Netty but now comes day of reckoning...

I got a plain java.net.Socket here (to be more specific, a custom SocketPoolFactory where Sockets are created along with a corresponding OutputStreamWriter and InputStreamWriter which wrap the socket's IO-Streams) and I need to monitor what is sent and received (in order to write this to the log file for debugging purposes). Seems like I have a tough time to figure out where to hook in and intercept what is sent/received.

Can somebody help? What's the best to do this? It is only for debugging (so does not need to be top notch efficient) (and if it helps somehow: I am working with Groovy).

Upvotes: 0

Views: 1072

Answers (1)

user207421
user207421

Reputation: 310884

Write your own FilterInputStream-derived class and interpose it in the stream stack attached to the socket,

Upvotes: 1

Related Questions