I have created proxy server. It runs on port 9000.
I made proxy settings in my web browser to handle the request coming at port 9000. When I hit any URL on Web browser then I read the data from socket InputStream and write thr data back to Socket outputstream.
When I print the response coming from the Web Browser it gives me data in unreadable format....
My issue is How can I append my response with the Incoming request from Socket and write it to another socket.......................
Please UseCodeTags when posting code of any length. It's unnecessarily hard to read as it is, making it less likely that people will do so. You can edit your post to include them.
Some things I noticed:
You may want to use a ServerSocket instead of a Socket for the server, especially if you want to handle multithreading later on
You're completely ignoring the issue of encoding, essentially assuming that the platform default encoding of the proxy server will be the same as the encoding of the web request or the web response, which is not a given. In fact, HTTP requests can be encoded using any number of encodings, so the proxy needs to be prepared to recognize the encoding before it can meaningfully transform the byte stream into characters.
The code seems to write the request as part of the response, which doesn't make sense - HTTP request and response use completely different headers, for a start.
I think you will benefit from thoroughly reading the HTTP specification for how HTTP requests and response may or should look like.