Creating java sockets behind proxy servers.

Hi,
I am trying to create a socket to an external server(i.e. a public server) from behind a proxy firewall, but the socket creation statement throws an IO exception. Can someone please let me know how to create sockets using proxy servers.
TIA
Shishir

I tried using java.net.Proxy for the connection. But the socket to the proxy itself is not getting created. It throws the IllegalArgumentException.
import java.io.*;
import java.net.*;
import java.net.Proxy.Type;
public class Client {
static Socket proxSocket = null;
static PrintWriter out = null;
static BufferedReader in = null;
public static void main(String[] args) throws IOException {    
try {
System.out.println("Trying to create socket");
InetSocketAddress proxyadd = new InetSocketAddress(InetAddress.getByName("148.87.19.20"),80);
Proxy ps = new Proxy(Proxy.Type.HTTP,proxyadd);
Socket proxSocket = new Socket(ps);
out = new PrintWriter(proxSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
proxSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: ...");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: ...");
System.exit(1);
catch(IllegalArgumentException e)
System.err.println("Unable to describe the proxy.");
System.exit(1);
}

Similar Messages

  • Creating a socket behind a proxy server

    How can I create a socket to a server if the client is behind a proxy server? I know java.net's HTTP-related classes have built-in proxy server support but this is not for a HTTP-based application.

    Hi,
    I also need to do this but not found any way yet. Somewhere I read that we can set the socket proxies (because mine was an application which tries to open socket connection over the network) through command line or by setting the system properties "socksProxyHost=<proxy_host_address>" and "socksPoxyPort=<proxy_port>". I tried to solve my proxy issue this way but all invain. While setting these system properties it is required that your proxy server is using the SOCKS service which I think is mostly the case but it still didn't work for me. You people try and c if it works for you. If anyhow you manage to get this issue resolved then please tell me also by posting a message.
    regards

  • Does Socket support proxy servers?

    Hello,
    I was wondering, if one was to create a Socket and then
    connect to a web site...
    mySocket.connect("www.mydoman.com", 80);
    but the user's PC uses a proxy server to connect to the
    Internet, would this
    connection succeed or fail?
    Also, I assume that the URLRequest / Loader classes do in
    fact get through proxy servers.
    Is that correct or not?
    Thanks for your insight.
    Dan

    Hi,
    Pls chk this;-->supported platforms for BO products
    https://websmp206.sap-ag.de/~form/sapnet?_SHORTKEY=01100035870000712240&_SCENARIO=01100035870000000202&
    Regards
    CSM Reddy

  • Sockets through proxy servers

    im facing a problem.in which I am having,one java application that is sitting behind Proxy1 has to access the Webserver which is sitting behind proxy2,for transfering files. from one M/C tht sitting behind Proxy 1 to the webserver sitting behind proxy 2.
    using URLConnection i will be able to do this,but as per my requirement i may have to transfer files which may be more than 100 MB,in that case URLConnection is failing because of OutofMemmory Error,
    the only way to cater this requirement is socket but i don't know hw i can go through proxy using java sockets......
    ---------------------------Proxy1------ Proxy2
    -------------------------- --|----------------|
    Java Application -------| <----->------|----- My WebServer
    -----------------------------|-- internet---|
    ---------------------------- |----------------|
    Thnx in advance,

    Thnx tolmank,
    i am using sockets instead of URLConnection,i was able to connect using URLConnection,but when i use sockets i am not able to,i cann't use URLConnection because of out of memmory problem,as i mentioned earlier .
    if anybody can me help me out it would have been a great help for me...
    thnx in advance......
    shafeek

  • How can i create a socket connection through an http proxy

    i'm trying to make a socket connection send an email - i have code that works when you don't have to go through a proxy server but i can't make it pass the proxy server.
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class Mail
    public String to_address = "[email protected]";
    public String from_address = "[email protected]";
    public String sendSub = "HeHeHe";
    public String sendBody = "hehehe - it worked";
    // This is created to allow data to be read in by the keyboard.
    BufferedReader in = new BufferedReader(
    new InputStreamReader(System.in));
         private void Mail(String to_address, // recipient's addresses
    String from_address, // sender's address
    String sendSub, // subject
    String sendBody) // Message
                   throws IOException, ProtocolException,      UnknownHostException {
         Socket socket;                // creates a Socket named socket
         PrintStream out;               // stream to write to socket
         String host = "imap.btopenworld.com";          // identification of the mail server host
    // creates a new socket for connection to the mail server
    // as well as two variables for the read and write streams
         socket = new Socket(host, 25); // opens socket to host on port 25 (SMTP port)
         out = new PrintStream(socket.getOutputStream());
    // read the initial message
         in.readLine();
    // Dialog with the mail server
    // send HELO to SMTP server HELO command is given by a connecting SMTP host
         out.println( "HELO " + host );
         out.flush() ;
         in.readLine();
    // Once we are connected to the mail server we start sending the email...
    // send "from"
         out.println( "MAIL FROM: " + from_address );
         out.flush() ;
         in.readLine();
    // send "to"
         out.println( "RCPT TO: " + to_address );
         out.flush() ;
         in.readLine();
    // prepare the mailserver to receive the data
         out.println( "DATA" );
         out.flush() ;
         in.readLine();
    // Send actual email
         out.println("From: " + from_address);
         out.println("To: " + to_address);
         out.println( "Subject: " + sendSub + "\n" );
         out.flush() ;
         out.println("");
         out.println( sendBody ) ;
         out.println(".") ; // standard to determine end-of-body
         out.flush() ;
         in.readLine();
    //Quit and closes socket
         out.println("QUIT");
         out.flush();
         in.close() ;
         socket.close() ;
         return ;
    public static void main (String [] args) throws IOException
    Mail themail = new Mail();
    }

    i've tried that but it doesn't seem to do nething - this is how i implemented it...
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class Mail
    public String to_address = "[email protected]";
    public String from_address = "[email protected]";
    public String sendSub = "HeHeHe";
    public String sendBody = "hehehe - it worked";
    // This is created to allow data to be read in by the keyboard.
    BufferedReader in = new BufferedReader(
    new InputStreamReader(System.in));
         private void Mail(String to_address, // recipient's addresses
    String from_address, // sender's address
    String sendSub, // subject
    String sendBody) // Message
                   throws IOException, ProtocolException,      UnknownHostException {
         Socket socket;                // creates a Socket named socket
         PrintStream out;               // stream to write to socket
         String host = "imap.btopenworld.com";          // identification of the mail server host
    // creates a new socket for connection to the mail server
    // as well as two variables for the read and write streams
         socket = new Socket(host, 25); // opens socket to host on port 25 (SMTP port)
         out = new PrintStream(socket.getOutputStream());
    // read the initial message
         in.readLine();
    System.getProperties().put( "proxySet", "true" );
              System.getProperties().put( "proxyHost", "144.124.16.28" );
              System.getProperties().put( "proxyPort", "8080" );
    // Dialog with the mail server
    // send HELO to SMTP server HELO command is given by a connecting SMTP host
         out.println( "HELO " + host );
         out.flush() ;
         in.readLine();
    // Once we are connected to the mail server we start sending the email...
    // send "from"
         out.println( "MAIL FROM: " + from_address );
         out.flush() ;
         in.readLine();
    // send "to"
         out.println( "RCPT TO: " + to_address );
         out.flush() ;
         in.readLine();
    // prepare the mailserver to receive the data
         out.println( "DATA" );
         out.flush() ;
         in.readLine();
    // Send actual email
         out.println("From: " + from_address);
         out.println("To: " + to_address);
         out.println( "Subject: " + sendSub + "\n" );
         out.flush() ;
         out.println("");
         out.println( sendBody ) ;
         out.println(".") ; // standard to determine end-of-body
         out.flush() ;
         in.readLine();
    //Quit and closes socket
         out.println("QUIT");
         out.flush();
         in.close() ;
         socket.close() ;
         return ;
    public static void main (String [] args) throws IOException
    Mail themail = new Mail();
    }

  • SOAP: call failed: java.io.IOException: unable to create a socket ??

    Hi
    I am getting the following error in PI for one of my sync interfaces.
    SOAP: call failed: java.io.IOException: unable to create a socket
    The interface works most of the time, but i get this error couple of times a day.
    Regards,
    XIer

    Hav you able to resolve this issue? Please let me know what was cause of this "unable to create a socket"
    Thanks,
    Sagar

  • SOAP Receiver   java.io.IOException: unable to create a socket

    Hi All,
    I have scenario where i invoke a external webservice  (over internet)  using SOAP adapter. I can reach the external target as they see my traffic on firewall but i always get:
    com.sap.aii.af.ra.ms.api.DeliveryException: java.io.IOException: unable to create a socket
    I cannot find any logs which provide more information on this. I have imported all the clients certificates into my J2EE keystore (webservice is over HTTPS). Any suggestions on where better logs can be found would be appreciated. So far checked RWB and the default trace log.
    Since my certificates arent in ABAP stack I cant use SM59 to test. I have used test tool like soapUI and can invoke the web service (although on different network to my XI server) so not sure why XI is failing
    Any suggestions would be greatly appreciated!
    Sorry forgot to mention - The error its self i suspect is firewall and will need to get network people to look at but any information on how to debug errors like this on J2EE side would be appreciated - is there a J2EE version of SM59?
    Message was edited by:
            Chris Mills

    Hi Chris,
    Check this thread..
    SOAP Adapter: java.io.IOException: unable to create a socket
    cheers,
    Prashanth
    P.S Please mark helpful answers

  • SOAP Adapter: java.io.IOException: unable to create a socket

    Hi,
    I am trying to use the soap adapter to connect to a URL and post a document. When I try, the adapter throws the following
    java.io.IOException: unable to create a socket
    Does anyone know what causes this?
    I get it both with the SOAP Envelope turned on and off.
    I am trying to post to a URL that is usually used for straight HTTPS posts, could this cause an issue? The only reason we are using the SOAP adapter is to be able to send attachments! Hence, SOAP adapter, no SOAP envelope.
    Kind Regard,
    Chris

    Hi,
    Had faced the same issue. The possible reasons were :
    1. Either the target server might not be responding.
    2. The Target URL configured in the communication channel might be wrong.
    3. The port to which the message is being sent might not be opened which you need to cross-verify.
    For me the issue was the port, which wasn't enabled from our end. The messages went past successfully once it was enabled.
    Cheers!!
    Jithin James.

  • Connect to socket server behind proxy?

    My socket server is behind proxy.
    Can client connect to server?
    Thanks

    Hi Sojan !
    Server work,
    but when run behind proxy=Exception.
    Hier is part of code.
    public static final int PORT=780;//port number
    static Socket soc;
    PrintWriter out;
    BufferedReader in;
    static boolean flag;//check connection
    try{
    ServerSocket ss=new ServerSocket(PORT);
    flag=true;
    while(flag){
    soc=ss.accept();
    v.in=new BufferedReader(new InputStreamReader(soc.getInputStream()));
    Thread d=new Thread(v);
    d.start();
    }catch(Exception z){z.toString();
    public void run() {
    try{
    while(flag){
    String g="";
    g=in.readLine();
    if(g==null){break;}
    //System.out.println(g);
    jTextArea1.append(g+"\n");
    catch(Exception c){
    System.out.println("soc2 closed");
    try{
    soc.close();
    }catch(IOException f){System.out.println("soc2 not closed");}
    ...

  • Connection Problem while client is behind proxy and server out side proxy

    hello
    i implemented ChatApplication in JAVA, for that i used socket connection when client and server both are in same network then it's working fine.
    but when my server is on internate and client is behind proxy and try to connect with server
    it not able to connect i get exception.
    i serch most of forum i got same answer and i try it but i was not success.
    any kind of help is appriciated.
    i attached my code(which i implement for testing ) pls reply me
    thanks in advance.
    Server.java
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    class Server {
       public static void main(String args[]) {
          String data = "you are successfully connected with server.";
          try {
             ServerSocket srvs = new ServerSocket(1234);
             Socket skt = srvs.accept();
             System.out.print("Server has connected!\n");
             PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
             System.out.print("Sending string: '" + data + "\n");
             out.print(data);
             out.close();
             skt.close();
             srvs.close();
          catch(Exception e) {
             System.out.print("Whoops! It didn't work!\n");
    ProxyClient.java
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class ProxyClient{
       public static void main(String args[]) {
         String host="61.17.212.29";
         int port=1234;
               String line;
         Properties properties = System.getProperties();
         /*properties.put("firewallSet", "true");
         properties.put("firewallHost", "192.168.0.1");
         properties.put("firewallPort", "808");*/
         properties.put("socksProxySet","true");
         properties.put("socksProxyHost", "192.168.0.1");
         properties.put("socksProxyPort", "1080");
         System.setProperties (properties);
         try {
         /*SocketAddress addr = new InetSocketAddress("192.168.0.1", 1080);
         Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
         Socket skt = new Socket(proxy);
         InetSocketAddress dest = new InetSocketAddress("61.17.212.29",1234);
         skt.connect(dest);*/
             System.out.println("before socket taken");
             Socket skt = new Socket(host,port);
             System.out.println("after socket taken");
             BufferedReader networkBin = new BufferedReader(new InputStreamReader(skt.getInputStream()));
             System.out.println("Received string: '");
             line = networkBin.readLine();     // Read one line
          while(true)
                 System.out.println(line);     // Output the line
                 line = networkBin.readLine(); // Read the next line, if any
          catch(Exception e) {
             System.out.print("Whoops! It didn't work!\n");
         e.printStackTrace();
    }

    Now look here. I could not care less about this
    code. I don't know anything about it, I don't
    want to know, I have already recommended you don't
    use it, and I have also given you a simpler and
    better solution. If you don't want to take my advice
    that is your privilege and your problem.ya i has understand system propertis i have setted and u can see it in the code i have tried by both system properties and also J2SE 5.0 proxy class but i got a same problem malformed Exception server refuse to connection.
    is there any problem at sever side?
    can u tell me in which way u r teling to set the propery i m looking forward for ur reply.
    ya i m sure u will give me.................reply "ejp".
    Thnx in advance.

  • Receiver SOAP channel error: Communication over HTTPS. Unable to create a socket

    Hi,
    I am getting following error while sending message from PI (7.1) to SalesForce system:
    'SOAP: call failed: java.io.IOException: Communication over HTTPS. Unable to create a socket'
    Scenario: Sending Customer data from SAP via Async proxy to PI which is sent further to SalesForce system via SOAP webservice call.
    When I am trying to Post data to the same webservice via SOAP UI it is working fine and data is getting updated in SalesForce system.
    XPI inspector logs for the channel suggest the following:
    client [103965] RequestImpl.initSslAttributes(): Initially sslAttributes = null
    client [103965] RequestImpl.initSslAttributes(): Cannot find SSL headers in the request.
    client [103965] RequestImpl.initSslAttributes(): No SSL attributes: not found in headers and not searched in FCA, because connection.isSecure() = false; sslAttributes = null
    I have checked the following SAP Note and requested for updation of SSL icm parameters
    891877 - Message-specific configuration of HTTP-Security
    I checked the following discussions:
    http://scn.sap.com/message/8910518#8910518
    http://scn.sap.com/message/6244674#6244674
    http://scn.sap.com/thread/2100000
    http://scn.sap.com/thread/1632114
    which are suggesting a different approach. Kindly suggest a way forward.
    Thanks,
    Vishwajeet

    This is related network issue.
    Did you do telnet in pi server with target system ip and port?
    If you use https then you need to install certificates.
    Check below threads
    http://scn.sap.com/thread/190299
    Unable to create socket error

  • DeliveryException: unable to create a socket

    Hi,
       We are using the Proxy-> XI -> SOAP scenario(Synchronus). I am able to see that the request message mapping has transformed the message in to the required format. But, when it is calling the SOAP adapter it is giving com.sap.aii.af.ra.ms.api.DeliveryException: unable to create a socket error. Can any one help us in knowing
    what exactly is the problem. We have used 'Do not use SOAP envelop' option in the SOAP receiver adapter.
    Thanks And Regards
    Sripathi G Yogesh

    hi,
    you can refer to thread for your issue
    Re: SOAP Adapter: java.io.IOException: unable to create a socket
    regards,
    ujjwal kumar

  • Getting through proxy servers

    Hello,
    Does anyone know if the URLRequest / Loader classes are able
    to connect through proxy servers? In other words, does Flash read
    the PC's proxy configuration and automatically use it?
    Also, I was wondering, if one was to create a Socket and then
    connect to a web site...
    mySocket.connect("www.mydoman.com", 80);
    but the user's PC uses a proxy server to connect to the
    Internet, would this
    connection succeed or fail?
    Thanks for your insight.
    Dan

    Check the links below out. I think it may help you out some.
    http://bugs.adobe.com/jira/browse/FP-519
    http://bugs.adobe.com/jira/browse/FP-673

  • Sun Java System Web Proxy Server (4.0.2) - manage server will not start

    In short here's the scenario and main problem.   
    a. Proxy admin server start - no problem
    b. Create a new manage server (no proxying - just testing it) using different port. It just won't start. No logs produced either.
    Here's the server.xml for the new manage server.
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
       Copyright (c) 2003 Sun Microsystems, Inc.  All rights reserved.
       Use is subject to license terms.
    -->
    <!DOCTYPE SERVER PUBLIC "-//Sun Microsystems Inc.//DTD Sun Java System Web Proxy Server 4.0//EN" "file:///E:/Sun/ProxyServer40/bin/proxy/dtds/sun-web-proxy-server_4_0.dtd">
    <SERVER>
        <PROPERTY name="accesslog" value="E:/Sun/ProxyServer40/proxy-server3/logs/access"/>
        <LS id="ls1" port="8083" servername="cbaob-b3-csddb1.adp1.cibc.pte"/>
        <MIME id="mime1" file="mime.types"/>
        <ACLFILE id="acl1" file="E:/Sun/ProxyServer40/httpacl/generated.proxy-server3.acl"/>
        <USERDB id="default"/>
        <FILECACHE enabled="true"  maxage="30" mediumfilesizelimit="537600" mediumfilespace="10485760" smallfilesizelimit="2048" smallfilespace="1048576" transmitfile="false" maxfiles="1024" hashinitsize="0"/>
        <CACHE enabled="true" cachecapacity="2000" cachedir="E:/Sun/ProxyServer40/proxy-server3/cache">
            <PARTITION  partitionname="part1" partitiondir="E:/Sun/ProxyServer40/proxy-server3/cache" maxsize="100" minspace="5" enabled="true"/>
    <GC enabled="true" gchimargin="80" gclomargin="70" gcleavefsfull="60" gcextramargin="30"/>
        </CACHE>
        <LOG file="E:/Sun/ProxyServer40/proxy-server3/logs/errors" loglevel="finest"/>
    </SERVER>
    Nothing seems to be wrong with this. The XML format follows the specified DTD.   
    Would appreciate any help.   
    Thanks.

    Thanks for your reply. Yes. This is really odd.
    Anyway to make the whole story short, i uninstall this proxy server 4.0.2 on this server (say server1) and try to reinstall a new proxy 4.0.13 but having odd problem (i have administration rights)
    Here it goes.
    a. CMD java -version is 1.4.2_XX
    b. Double click the proxy 4.0.13 setup.exe - nothing happen.
    c. CMD setup --javahome c:\jdk1.6_XX - nothing happen
    Here retrying.
    a. Login to server2 and map conection to server1
    b. Double click the proxy 4.0.13 setup.exe on server1 (while on server2) - setup.exe runs. This proves the proxy setup.exe on server1 is good.
    c. Make a copy of proxy 4.0.13 on server2
    d. Login to server1 and map connection to server2
    e. Double click the proxy 4.0.13 setup.exe on server2 (while on server1) - setup.exe did not run.
    Both servers are on the same domain and i'm using same ID to access both servers
    Again, no logs on the windows events (security, application, system)
    This is becoming mind a boggling mystery.
    Any idea what's going on?
    Thanks.

  • Java Sockets Question

    Hi Guys,
    I've got a problem. I'm using raw socket connections for Web and other queries. I know I can use URLConnect and similar but they do not provide the flexiblity that I need so please do not suggest that I use those isntead.
    My problem is that I can set the read timeout (socket.setSoTimeout) and I can set the write timeout (socket.setLingerTimeout) but I there does not appear to be a setting to set the connection timeout.
    I'm using this for proxy servers, and the proxy servers tend to die quite often and when I try to connect to a server that no longer works the connection request just sits there forever, never actually times out. Now, the timeouts work fine on the read/write but not on the connection.
    I know I can create another thread that's a timer and force close the socket thread but that doesn't seem like the proper way to do it.
    Thanks,

    Great. Thanks, Played with that overloaded constructor and finally got it to work under linux. The funny thing is it wouldn't work under windows when I was testing because windows uses its own timeout.

Maybe you are looking for

  • Down payment against Purchase order

    Hi SAP GURU i have one queries regarding down payment made against asset puchase order I created one asset code, create the PO with accoun assignment categories A, made a advance payment against reference to this PO no . when i enter the po number in

  • NameTrans pfx2dir with 'from' as wildcard?

    Hi, Is it possible to use a wildcard in the 'from' parameter of a pfx2dir NameTrans directive? This is with Web Server 6.1. I've tried all sorts of ways but nothing seems to work. What I'm trying to do is convert several permutations of a URI, e.g.:

  • ALV display hints...

    hello guys... can any one tell me how to use alv display hints... like while displaying the headings in the output, if the heading is too long they need in short form ie if its "CHILD Parent Value" then in output it must show "CPV",  BUT when the bri

  • Adobe interactive forms using ABAP

    Hi, Anyone could help me to develop Adobe interactive forms (online and offline cases)   using ABAP (not Java). I would need <b>step by step procedures</b> to develop quickly. Thanks. Ramana reddy

  • Nokia E63 won't update, error code 12017

    I can't update my Nokia E63 using the ovi suite software. After doing a complete memory wipe, the same error code appears during the update process. I select update 501.21.001, hit install... but before the download can even begin I get error code 12