Http over socket

Hi All,
Can you give me advice on how to program a http client connecting through a socket proxy in Java?
Thanks,
Jack

Hi Esmond,
My apologies for not having explained what I am trying to achieve. Let's look at the following code where I am trying to connect (http) to Tor network which treats Java application as Socks proxy client:
TorJavaWithNoProperty.java
1.       u = new URL("http://check.torproject.org");
2.       HttpURLConnection connection = (HttpURLConnection) u.openConnection();
3.       connection.connect(); .....
The connection was successful when running with the following syntax:
java -DsocksProxyHost=localhost -DsocksProxyPort=9050 -cp . TorJavaWithNoProperty
On the other hand, I did not get a successful connection when trying to set the above properties within the code below:
TorJavaWithProperty.java
1.       SocketAddress addr=new InetSocketAddress("localhost", 9050);
2.       Proxy proxy=new Proxy(Proxy.Type.SOCKS,addr);
3.       Socket torSocket=new Socket(proxy);
4.       InetSocketAddress final_addr=new InetSocketAddress("http://check.torproject.org", 8080);
5.       torSocket.connect(final_addr);The error output below gives:
java.net.SocketException: SOCKS server general failure
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:526)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at noproxy.TorJavaWithProperty.main(TorJavaWithProperty.java:5)
In other word, Tor uses "localhost" as its socksProxyHost but can you see why TorJavaWithProperty.java is not working?
Thanks,
Jack

Similar Messages

  • What is the advantage of using RMI over socket connection

    plz tell me guys what is the advantage of using RMI over socket connection bcoz inherently RMI also uses socket connection.so what is the exact difference in between thm and what is the advantage of using RMI over socket connection.

    i knew tht bt i http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal — in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Can't open HTTP server socket on port 50000 in dispatcher

    We get the following message in the console_log for the dispatcher.
    ID000544: Error starting service http. Can't start the service due to java.io.IO
    Exception: Can't open HTTP server socket on port 50000
    [ServiceManager]: ID000544: Error starting service http. Can't start the service
    due to java.io.IOException: Can't open HTTP server socket on port 50000
    [Framework -> criticalShutdown] Service http startup error!
    Anyone have any ideas what might be the problem?
    Thanks,
    Keith

    Hello Keith,
    this errors occurs when the port http 50000 is already taken. Please could you check if this port on your machine is free or an other dispacther instance is already started on same machine. You can change the port in sap j2ee config tool (dispatcher-> services->http)
    Best Regards,
    Fabrice

  • Synchronizing peers in transfer over Socket

    Hi again!
    I'm relatively new to Java, so there are many issues I still have to figure out ;-)
    Here are two of them:
    1) How can peers be synchronized in transfer over Socket? For example:
    This is the receiving peer:
    DataInputStream dsin = new DataInputStream(socket.getInputStream());
    String s = dsin.readUTF();This is the sending peer:
    DataOutputStream dsout = new DataOutputStream(socket.getOutputStream());
    dsout.writeUTF("something...");
    dsout.close();At the receiving peer in some cases the EOFException or SocketException (Socket closed) are raised. I suspect this happens either because the receiver tries to read input before it is fully transfered or when the sender already managed to close the socket's OutputStream.
    So how can such a transfer be synchronized?
    2) What if both peers close their socket's OutputStream? Does this result in closing the connection and releasing all its resources, such as port?
    Thank you everyone!

    this is what I learnt:Sorry, try again!
    DO NOT close the Socket on any endpoint until you make sure that the other endpoint managed to call socket.getInputStream().This 'rule' is quite unnecessary.
    According to the documentation, getInputStream() may return a stream which buffer was discarded by network software if a broken connection was detected.That's a complete misreading and misquoting of the documentation. A reset can happen to the connection at any time; can cause loss of data from te socket receive buffer; and has nothing to do with the operation of getting the input stream. Getting the input stream of a socket has nothing to do with the network or the state of the connection. It just constructs a Java object. So this rule is quite pointless.
    Even more, it seems to be a good practice not to close the Socket until you are sure that the other endpoint will not try to read from the channel.You've got that back to front as well. THink about that some more and you will see it involves an infinite regression.
    The only rules you need are these:
    (a) don't close the socket until you're sure the other end has finished writing. You have to close the socket while the other end is still reading, so that it will get a EOS indication, so it will know you've gone away, so it will stop writing and close its end of the socket.
    (b) closing the socket or either of its streams closes the other two items. You should always close the topmost output stream of a socket and nothing else.

  • Is there way to set tofirefox4 to always use https over http?

    is there way to set tofirefox4 to always use https over http? instead of getting the message if i want to go to https site instead of http site, is there a way so that firefox will notify me if there isn't a https site instead?

    *Force-TLS: https://addons.mozilla.org/firefox/addon/force-tls/
    *STS UI: https://addons.mozilla.org/firefox/addon/sts-ui/
    *HTTPS Everywhere: http://www.eff.org/https-everywhere

  • Send XML over Sockets

    I am beginning and I need to send XML formatted data from Swing Client to Server for parsing/processing/and response.
    There are no web server available to use. I think its best to use socket connection, but how do I send xml data over socket, and how do I receive it from server and parse it?
    I have read and cannot find a similar example.

    Xerces has DOMSerializer which can be used to serialize a Document object to a string. Once it's a string it's trivial to transmit over a socket connection. On the other side, to parse it, you'll have to create a StringReader for the received string and then an InputSource from the StringReader. You'll then be able to pass the InputSource to the DocumentBuilder.parse( ) method to generate a Document on the receiving side.
    Hope that helps,
    - Jesse

  • Filetransfer over sockets

    hi,
    im currently working on a filetransfer over sockets. this is what i do:
    i have a connection from the client to the server. on both sides i have a PrintStream for the output and a bufferedReader to read the responses. the client asks for a file and the server answers with the md5-hash size of the file, so that the client knows how many bytes it has to read. that works fine.
    now the filetransfer:
    the server writes the bytes of the file directly to the OutputStream (not the PrintStream). the client opens a BufferedInputStream on the mentioned socket and reads in as many bytes, as the server said before.
    now the problem:
    sometimes the filetransfer works fine, but sometimes some bytes are missing. i wonder where they are gone. it cant be a problem with the flush() method, because im using OutputStream to send the data. (i tested BufferedOutputStream with flush() with the same results).
    maybe it's not working because a attached a BufferedReader and a BufferedInputStream to the InputStream on the client-side...
    does anybody know, whats going wrong?
    let me know if you want to see some code.
    greetings,
    henrik

    i have solved this problem by using java.nio

  • SA520: problem when trying to access HTTPS over custom port in a site-to-site vpn

    We've set up a site-to-site VPN between our SA520 and our SmoothWall running at our data center. The tunnel is always connected, so that part runs fine
    What works fine:
    - Client 192.168.11.1 is able to start an RDP session (on it's default port 3389) to server 192.168.3.5
    - Client 192.168.11.1 can open a webpage which is hosted on server 192.168.3.5 (hosted on the default HTTP port 80)
    What doesn't work:
    - Client cannot open web page which is hosted on server 192.168.3.1 at the following url: https://192.168.3.1:441
    - or, for that matter, any https service in the 192.168.3.x LAN which runs on a different port
    To summarize:
    from the 192.168.11.x subnet, accessing services running on default ports (i.e. 80, 3389, 21) in the 192.168.3.x subnet works fine. doing the same for services running on custom ports (i.e. https over port 441) the connection to the webserver times out.
    Thanks in advance for any help you may provide.
    Glen

    hi luis,
    thank you for your reply. we've checked the smoothwall configuration, but couldn't discover anything which could cause this problem. we even tried replacing the sa520 with a draytek vigor router to set up an lan-to-lan vpn with the smoothwall. with the draytek in place we have no problems accessing the aforementioned servers, so it seems the issue is with the SA520.
    what exactly do you mean by creating an ACL from the remote WAN to our LAN? i assumed you meant creating a firewall rule, allowing traffic from the remote device's public ip to our LAN. however, in that case i need to enter an ip address of a device in our LAN, or else i cannot save this rule. as a test i entered the ip address of my machine as the destination address, but am still unable to access the aforementioned servers.
    here's how i set up the rule:
    from zone: UNSECURE (WAN/optional WAN)
    to zone: LAN
    service: ANY
    action: ALLOW always
    schedule: (not set)
    source hosts: Single address
    from: public ip of one of the aforementioned servers
    source NAT settings > external IP address: WAN interface address (cannot change this setting)
    source NAT settings >WAN interface: dedicated WAN (cannot change this setting)
    destination NAT settings > internal ip address: 192.168.11.123 (ip address of my machine)
    enable port forwarding: unchecked
    translate port number: empty
    external IP address: dedicated WAN

  • URGENT : Pass non-serializable objects over sockets

    I am working with a non-serializable class.I can't change it to serializable(since it's an API class).I can't create a subclass either as I need to pass the same exact Object .I have tried wrapping it in a serializable class (as transient )but then the particular object that I need is not serialized.Is there a way to pass non-serializable objects over sockets?.Some other way of doing this?. Should i use RMI or Externalize?. Any help would be appreciated.

    {snip}
    Like this:
    public class SerializableLibraryClass extends
    LibraryClass implements Serializable {
    }Then you've got a class that is exactly the same as
    LibraryClass, but is now serializable.Not quite. The base class still isn't Serializable. Take, for example, the following code:
    public class A
        public int a1;
    public class B extends A implements Serializable
        public int b1;
    B beforeSend = new B();
    beforeSend.a1 = 1;
    beforeSend.b1 = 2;
    objectOutputStream.writeObject(b);
    B afterSend = (B)(objectInputStream.readObject());Both beforeSend and afterSend have fields a1 and b1. For beforeSend, a1 = 1 and b1 = 2. For afterSend, b1 = 2 but a1 = 0. The superclass wasn't Serializable; therefore, its members weren't Serialized and, when the object was created on the other side of the stream, a1 was left at its initial value.
    In short, you can't just Serialize the subclass. That Serialization won't apply to its superclasses.

  • Pass non-serializable objects over sockets

    I am working with a non-serializable class.I can't change it to serializable(since it's an API class).I can't create a subclass either as I need to pass the same exact Object .I have tried wrapping it in a serializable class (as transient )but then the particular object that I need is not serialized.Is there a way to pass non-serializable objects over sockets?.Some other way of doing this?.

    Have you considered leaving it in situ and using RMI to manipulate it remotely ?
    To be a little pedantic, if you need the "same exact object" then there's no technique that will work for you, since you can only copy an object between JVMs, not move it.
    D.

  • Mail HTTP over RPC setting

    I just bought a new iMac... and have question with my mail set up.
    My company use MS exchange server with HTTP over RPC setting. They gave me a list of Exchange Server name, http:// ......, msstd:.... it works fine in my old PC Outlook and I don't know how to set this up in my new iMac. I can't found those option in iMail or Entourage mail account setting. Help!!!
    Thanks

    Apple Mail does not support RPC over HTTP. Entourage does not either, however, I think I saw something about using WebDAV in Entourage to get the same type of functionality. Is IMAP configured on your exchange servers? You can ask the IT group.

  • HTTP over UDP?

    Has anybody done this before?? could you provide me with some links? And one very basic question, does HTTP expect any information from TCP with respect to acknowledgment and all those stuff or everything handles by TCP??
    Thanx

    Though I'd say that in the real world, the packet size
    should be smaller because of the limitations of
    transmission. As a packet that size will have to be
    broken up to fit even over ethernet.If IP fragmenting is enabled such a large UDP packet might work. However most UDP applications that I have seen keep the total packet size to somewhat less than 512 bytes to avoid fragmenting and the problems associated with hosts that cannot handle it. If you are on an all ethernet network you should be able to use up to the size limit of ethernet packets (I forget the exact number but it is about 1400 bytes) minus the headers.
    HTTP really requires a bi-directional stream (which TCP gives you) for a full implemtation. However some technologies (like uPnP) run a restricted subset of HTTP over UDP.

  • Problem with Sending files over Sockets

    Hi. I have a problem when I try to send files over sockets. When I send text files it works well but when I try to send .jpg or other kind of files it doesn't work well because some characters are wrong, I hope you can help me.
    Here is my code:
    //Sender code
    import java.io.*;
    import java.net.*;
    class Servidor{
         Servidor(){
              try{
                   String arch="art.jpg";
                   ServerSocket serv=new ServerSocket(125);
                   Socket socket=serv.accept();
                   System.out.println("Conectado");
                   int c;
                   BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                   FileInputStream fis=new FileInputStream(arch);
                   File f=new File(arch);
                   bw.write(""+f.length());
                   bw.newLine();
                   bw.flush();
                   System.out.println("Escribiendo");
                   while((c=fis.read())!=-1){
                        bw.write(c);
                   bw.flush();
                   fis.close();
                   System.out.println("Terminado");
                   while(true){
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Servidor();
    //Client code
    import java.io.*;
    import java.net.*;
    class Cliente{
         Cliente(){
              try{
                   Socket socket=new Socket("localhost",125);
                   System.out.println("Conectado");
                   BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                   long tam=Long.parseLong(br.readLine());
                   long act=0;
                   FileOutputStream fos=new FileOutputStream("resp.jpg");
                   System.out.println("Recibiendo: "+tam);
                   while(act<tam){
                        fos.write(br.read());
                        act++;
                   System.out.println("Terminado: "+act+" / "+tam);
                   fos.close();
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Cliente();
    }

    I don't think you want BufferedReader and OutputStreamWriter, you want ByteArrayOutputStream and ByteArrayInputStream . The problem is that you are sending jpegs (binary data) as text.

  • Image over sockets

    Hello,
    What I'm basically trying to do is to send an Image among strings over sockets.
    I have a serializable object and I'm sending back and forth. In this object I have an ImageIcon but when I try to send it to the client I'm getting the following error on the server-side:
    failed to load image contents
    java.io.IOException: failed to load image contents
    at javax.swing.ImageIcon.writeObject(ImageIcon.java:418)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
    at ThreadedDataObjectHandler.run(ThreadedDataObjectServer.java:90)
    line 90: out.writeObject(myObject); // myObject is the serializable objectout is:
    ObjectOutputStream out=new ObjectOutputStream(incoming.getOutputStream()); any ideas on how to fix this??
    Thanks
    -rolo

    Exception says "java.io.IOException: failed to load image contents"
    most probably you are trying to send an image which has had an eror when loading the image.
    See the image load status of the image icon.

  • Enable HTTP Over SSL: New documentation

    Hi,
    Fyi, a new article has been published in the CQ5.5 documentation:
    Enabling HTTP Over SSL
    hope that helps 
    scott

    Enable ssl for HTTP
    In the administration guide, you shoud find this
    you have to modify ssl.conf to enable ssl, as well in th eopmn.xml there is an option for enable ssl. but more accurant check the guide.
    http://download.oracle.com/docs/cd/B14099_19/core.1012/b13995/sslmid.htm#CHDDGBGF

Maybe you are looking for

  • SSL VPN (WebVPN) issues with IOS 15.0(1)M1

    Hello everyone... I need your help! I am having some weird issues with webvpn/anyconnect, please find the relevant information below; Symptoms: - AnyConnect Client prompts users with the following error: "The secure gateway has rejected the agent's V

  • How can I create a filter from a contact list?

    I have a lot of classes that I teach. I have created an email contact list for all of my individual classes, which I would like to create a single fitler for each of these list, in order to put them into a corresponding folder. It would save me a lot

  • Error while posting in PRFI (Travel Management)

    Hi Experts, I am facing a problem while posting travel expenses to FI, when i execute PRFI i am getting a message "For the ISO code INR there is no unique SAP currency code for ALE". It is not an error message and trip will be posted with postable am

  • How to recover a playlist accidentally deleted in iTunes 10

    Could someone PLEASE HELP ME on "How do I recover a playlist that I accidentally deleted in iTunes 10?

  • Business rule XML facts not visible soa  11.1.1.6.0

    Hello experts, Here comes the description of steps: When dragging a business rule with input and output facts defined(xsd:complexType), in bpel 2 process, in the edit rule dialog box: click on either of the assign input & output tabs to add a copy ru