wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes How to append response to the incoming request from Socket and write to another Socket..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to append response to the incoming request from Socket and write to another Socket....." Watch "How to append response to the incoming request from Socket and write to another Socket....." New topic
Author

How to append response to the incoming request from Socket and write to another Socket.....

Singh Vaibhav
Greenhorn

Joined: Jul 31, 2008
Posts: 3
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.


Now I want to append some response (in the form of Javascript) with the Incoming request but when I write the response I can't see any code embedded in the web browser.

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.......................
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42600
    
  65
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.


    Ping & DNS - my free Android networking tools app
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to append response to the incoming request from Socket and write to another Socket.....