How to change HttpURLConnection to socket connection in java

hello i have a problem about a socket connection can you help me
i want to change HttpURLConnection connection to socket connection
here is
          java.net.URL url = new java.net.URL("http://64.74.75.74/approot/webapp/ZOR/bare");
          connection = new sun.net.www.protocol.http.HttpURLConnection(url, " ", 0);
          connection.setRequestMethod("POST");
          connection.setDoInput(true);
          connection.setDoOutput(true);
          connection.setUseCaches(false);
          java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(connection.getOutputStream());
          out.writeObject(getTextFieldGiden().getText());
          out.flush();
          out.close();
          return (String) (new java.io.ObjectInputStream(connection.getInputStream()).readObject());
how can i change it to
socket connection
thank you very much

The class you mention uses a Socket connection.
If you read the source you will see how it does it.
If you use a debugger yu will see the code which is most relevent.

Similar Messages

  • HttpURLConnection vs Socket connection

    Hi. what are the main differences between the two types of network connections i can do in java? i would like to know some pros and cons between the two but cant seem to find any articles based on it and was wondering if any one with experience with network program can help me.
    thanks in advance

    jonney69 wrote:
    Subject: HttpURLConnection vs Socket connection
    what are the main differences between the two types of network connectionsApples and orchards.
    HTTP
    On the internet, the communication takes place over a TCP/IP connection. This does not preclude this protocol being implemented over any other protocol on the internet or other networks. In these cases, the mapping of the HTTP request and response structures onto the transport data units of the protocol in question is outside the scope of this specification. It should not however be at all complicated.
    types of network connections i can do in java?You can do TCP/IP (plain sockets) or UDP/IP (datagram sockets)
    i would like to know some pros and cons between the two
    but cant seem to find any articles based on it and was wondering if any one with experience with network program can help me.You can probably find TCP/IP vs. UDP/IP comparisons.
    You can probably find HTTP vs. FTP comparisons.

  • Socket connection between Java and C

    I want to establish socket connection between Java client and C server (on Unix). Can anybody tell how to do it? Will the socket created in client be available in server. I tried out but there was no response from the server.

    We too can't connect the daemon server written by "c". The phenomena is below.
    << Execution of this Question1.class >> ---------------------------------------
    [kazuyuki@CryptOne tmp]$ java Question1 E 1.2.3.4 MFrame.java 195.211.1.1 15021
    << Output message >> ----------------------------------------------------------
    Quetion1 : flg_ = E
    Quetion1 : key_ = 1.2.3.4
    Quetion1 : fn_ = MFrame.java
    Quetion1 : adr_ = CryptOne.localhost/195.211.1.1
    Quetion1 : port_ = 15021
    java.net.ConnectException: Connection refused
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:350)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:137)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:124)
         at java.net.Socket.<init>(Socket.java:268)
         at java.net.Socket.<init>(Socket.java:122)
         at Question1.UPLOAD(Question1.java:65)
         at Question1.main(Question1.java:155)
    << Question >> ----------------------------------------------------------------
    Why the event "java.net.ConnectException: Connection refused" has occured ?
    The server to connect from Question1 can accept the connection request from
    the client program coded by "c" program. We have written down the daemon server
    program by "c" code tcp/ip socket functions (socket, bind, listen, accept).
    Security manager admits the access from this Question1.class, we have checked.
    Would you like please answer this Connction refuse occurrence ?
                                                                     2002.05.18 11:50:00.0(JST)
                                                                     K.Masuda
    << Java client code>> -------------------------------------------------
         (c)Copyright     All rights reserved.
              K.Masuda     2002.05.18
                   << Question1.java >>
    import     java.lang.String;
    import     java.io.InputStream;
    import     java.io.OutputStream;
    import     java.io.DataInputStream;
    import     java.io.DataOutputStream;
    import     java.io.FileInputStream;
    import     java.io.FileOutputStream;
    import     java.io.IOException;
    import     java.io.FileNotFoundException;
    import     java.net.Socket;
    import     java.net.InetAddress;
    import     java.net.UnknownHostException;
    import     java.net.ConnectException;
    import     java.net.NoRouteToHostException;
    class Question1 {
         char               flg_;
         String               key_;
         String               fn_;
         InetAddress          adr_;
         int                    port_;
         Socket               sock_;
         Question1(
              char          flg,
              String          key,
              String          fn,
              String          adr,
              int               port
              flg_     = flg;     
              key_     = key;
              fn_          = fn;
              try{
                   adr_     = InetAddress.getByName( adr );
              catch( UnknownHostException e ){
                   e.printStackTrace();
              port_     = port;
    System.out.println( "Quetion1 : flg_ = " + flg_ );
    System.out.println( "Quetion1 : key_ = " + key_ );
    System.out.println( "Quetion1 : fn_ = " + fn_ );
    System.out.println( "Quetion1 : adr_ = " + adr_ );
    System.out.println( "Quetion1 : port_ = " + port_ );
         public void UPLOAD(
              try{
                   sock_     = new Socket( adr_, port_ );
                   UpLoad();
                   DnLoad();
                   sock_.close();
              catch( UnknownHostException e ){
                   e.printStackTrace();
              catch( ConnectException e ){
                   e.printStackTrace();
              catch( NoRouteToHostException e ){
                   e.printStackTrace();
              catch( IOException e ){
                   e.printStackTrace();
         public void UpLoad(
              byte[]                         buf          = new byte[ 512 ];
              int                              rlen;
              int                              wlen;
              try {
                   OutputStream          sos          = sock_.getOutputStream();
                   FileInputStream          fis          = new FileInputStream( fn_ );
                   DataInputStream          dis          = new DataInputStream( fis );
                   DataOutputStream     dos          = new DataOutputStream( sos );
                   while( ( rlen =     dis.read( buf, 0, buf.length ) ) >= 0 ){
                        dos.write( buf, 0, rlen );
                   dis.close();
                   dos.close();
                   fis.close();
                   sos.close();
              catch( IOException e ){
                   e.printStackTrace();
         public void DnLoad(
              byte[]                         buf          = new byte[ 512 ];
              int                              rlen;
              int                              wlen;
              try {
                   InputStream               sis          = sock_.getInputStream();
                   FileOutputStream     fos          = new FileOutputStream( fn_ + ".cry" );
                   DataInputStream          dis          = new DataInputStream( sis );
                   DataOutputStream     dos          = new DataOutputStream( fos );
                   while( ( rlen =     dis.read( buf, 0, buf.length ) ) >= 0 ){
                        dos.write( buf, 0, rlen );
                   dis.close();
                   dos.close();
                   fos.close();
                   sis.close();
              catch( IOException e ){
                   e.printStackTrace();
         public static void main(
              String[] args
              char[]     chrs     = ( new String( args[ 0 ] ) ).toCharArray();
              Question1     clnt     = new Question1(
                                                                     // E or D
                                            chrs[ 0 ],
                                            args[ 1 ],               // key string
                                            args[ 2 ],               // file to be processed
                                            args[ 3 ],               // IP address
                                                                     // port
                                            Integer.parseInt( args[ 4 ] )
              clnt.UPLOAD();
    }

  • How to Changing Productive Client in an ABAP+Java System?

    How to Changing Productive Client in an ABAP+Java System?

    1. Log on to the ABAP system.
    2. Call transaction SPRO.
    3. Go to SAP Solution Manager Implementation Guide -->
    SAP Solution Manager --> Basic Settings --> SAP Solution Manager
    System --> General Settings --> Client Copy
    4. Perform the following steps:
    a) Maintain Profile Parameters
    b) Create Client
    c) Copy Client 000
    d) Convert UME

  • How i can make  my own connection in java source of a jsp page

    How i can make my own connection in java source of a jsp page (How to get connection from JNDI datasource address) ?
    imagine that i have a rowset in a web page , now i want to do some operation using
    plain JDBC , so i will need a connection object.
    I tried to get one of my rowsets connection but it return null ?
    what is best way to retrive a connection from JNDI datasource that we define for our project?
    for example if i have
    myRowSet.setDataSourceName("java:comp/env/jdbc/be");
    in web page constructor
    now i want a pure connection from the same datasource ? JNDI
    Thank you

    It is not hard to get your own connection from datasource.
    in your case you need to do like the the following code.
    i provide sample to show you how to catch the exception and create an statement .
    Connection con =null;
    try{
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/be");
    con = ds.getConnection();
    java.sql.Statement st =con.createStatement();
    }catch(SQLException sqlex){
    sqlex.printStackTrace();
    sqlex.getNextException().printStackTrace();
    catch(NamingException nex){
    nex.printStackTrace();
    hth
    Masoud kalali

  • How to change heap memory size for general java applications (not applets)

    Hi. I made a java class which manipulates images and I sometimes get an out of memory error when the files are large. In these cases I can run it successfully from the command line using:
    java -Xms32m -Xmx128m myappbut as I run this class from a firefox extension, I can't use this technique.
    Could some one tell me how to set this globally? I've found a lot of info on setting it for applets in the control panel but that's it. I also tried editing my deployment.properties file by adding:
    deployment.javapi.jre.1.6.0_11-b03.args=-Xmx128mbut none of these options seem to work.
    Thanks for any help.

    Also you can use use [JAVA_TOOL_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#tooloptions], with more documentation here. JAVA_TOOLS_OPTIONS is available since 1.5. There is no direct documentation on [_JAVA_OPTIONS|http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html] but was made available since at least 1.3.
    The recent existing forum thread [Java Programming - How to change the default memory limits for java.|http://forums.sun.com/thread.jspa?threadID=5368323&messageID=10615245&start=36] has a long discussion on the issue.
    You specified you are not using applets, but if you do, I would also suggest you use the next Generation Plug-in (since 1.6.0_10) that allows you specify the max memory in the applet without having to instruct the user how to make the change. See [JAVA_ARGUMENTS|https://jdk6.dev.java.net/plugin2/#JAVA_ARGUMENTS] for applets. Java Webstart uses resources.

  • 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();
    }

  • How to know if a socket connection is open ?

    Hi,
    I have a ftp class that opens a socket connection to a ftp server. Sometimes the connection is closed and I get an exception. There is any way to know if exists an open connection ?
    Thanks !

    From SDK v1.3.1 for abstract Class SocketImpl:
    Method connect
    protected abstract void connect(InetAddress address,
                                    int port)
                             throws IOException
        Connects this socket to the specified port number on the specified host.
    Parameters:
    address - the IP address of the remote host.port - the port number.Throws:
    IOException - if an I/O error occurs when attempting a connection.... So if it throws an exception on inception, it's NOT connected - NOT open, right? This is the class you've subclassed to create the socket connection? If not, which?

  • Problem with socket connection through Java Embedding...

    We are trying to create a simple socket connection to a socket server through BPEL PM using the Java Embedding component.
    BPEL Process : Client makes an asynchronous request. Passes an input variable. The input variable is sent to the Server Program through a socket connection through the Java embedding component.
    Server: We are running a simple Socket Server program from command prompt.
    The code below works fine as long as we do not try to receive a response from the server (Commented Code).
    If we uncomment the code and try to receive a response, it refuses to create an instance for the BPEL Process. And sometimes restarts the BPEL Server.
    Client Code:
    String msg="NONE";
    try{
    org.w3c.dom.Element input = (org.w3c.dom.Element) getVariableData("inputVariable","payload","/client:clientProcessRequest/client:input");
    msg = input.getNodeValue();
    Socket clientsoc=new Socket("ServerIP",1000);
    PrintWriter out1=new PrintWriter(clientsoc.getOutputStream());
    out1.write(msg);
    out1.flush();
    BufferedReader cin1=new BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
    msg=cin1.readLine();
    setVariableData("outputVariable","payload","/client:result",new String(msg));
    clientsoc.close();
    catch(UnknownHostException e)
    System.err.println("Don't know about host: dev.");
    System.exit(1);
    catch (IOException e)
    System.err.println("Couldn't get I/O for "+ "the connection to: dev.");
    System.exit(1);
    }

    Repost

  • How to change the Data base connection Dynamically

    Hi
    Hi create a crystal reports using crystal report 12.0 in this i use the standard wizard and local data base connection and create a dotnet programme for this .Now i want to  change the database because because i want to instal it in client they use a different connection so i need to change the connection .How is it possible . PLzzzzz tell me it is urgen t
    Addvance thnks

    Hi
    To change the database you can use DataSource  Option that is present in the Menu Bar.
    Go to Database
    ->Set Datasource Location
    ->Replace the current Data Source with the new Datasource.
    Hope this helps
    Shraddha

  • How to change com.sap.aii.connect.integrationserver.r3.mshost

    Hello Colleagues,
    java system is down,i want to change the com.sap.aii.connect.integrationserver.r3.mshost -81xx in configtool.
    can u please tell me  where to change in configtool???

    Hello
    >
    Raj_kumar330 wrote:
    > waiting for reply???
    Please have some patience. It is unrealistic to expect a response within 17 minutes of creating a thread.
    If your java engine is down, it does not possible to access the Exchange Profile URL. Is it absolutely necessary that you change this parameter before the java engine issue is resolved? Why not wait until the java engine is back up and then make the change?
    Regards
    XI/PI Moderator

  • I can't figure out how to change a PC address connection on a button

    I'm a new user of Lookout. I'm working on an existing application. I can see PLC connections on analog entry and display items, but I don't see how to look at and alter the connection of pushbuttons. They all seem to be local but i know from looking at the PLC program that they are connected to the PLC address. I'm feeling kind of stupid.

    If they are local, you will need to find the driver object, right click and clock Edit Connections, then find the connection.
    Another way find the connection is to use the Connection Browser, under Objects.
    Good luck!
    Forshock - Consult.Develop.Solve.

  • How to change standard start page of AS Java

    Dear experts,
    could you please tell me - is it possible to change the start page of the SAP J2EE server (which is shown when you go to the http://<server name>:50+<system number>*100  page -
    SAP Help Portal, System information, User Management etc.)?
    Is it possible to change it to the customer page?
    I thought it is connected with HTTP provider service, but the root directory pointed where
    doesn't exists in the server (.../j2ee/docs),
    so I don't understand, from what source the standard page is retrieved and shown to the user.
    Thanks a lot!
    Andrey.

    Hello Ventsi,
    thanks a lot for clearing of the situation.
    In fact we have a question - how to show the static web page which is stored on the J2EE server instead of the standard index.html. It is not an application, but simple html page.
    In HTTP provider help we can see the following lines -
    Root Directory
    The root directory for this host. The installation program does not create the main directory for the HTTP files automatically. It must be created additionally, or the path must be redirected to an existing directory. 
    Value  ../../docs
    Start Page
    This page is displayed when the browser establishes a connection with the host. The server searches the root directory for a file that appears in the Welcome Files list. The first match found is returned to the client browser.
    So does it mean that we have to create docs directory manually and put our file into this directory? 
    Or it is the wrong approach?
    Thanks!
    Regards,
    Andrey.

  • Detect loss of socket connection using java.nio.channels.Selector

    I'm using the nio package to write a "proxy" type application, so I have a ServerSocketChannel listening for incoming connections from a client and then create a SocketChannel to connect to a server. Both SocketChannels are registered to the same Selector for OP_READ requests.
    All works fine, until either the client or server drops the connection. How can I detect this has happened, so my proxy app can drop the other end of the connection ?
    The Selector.select() method is not triggered by this event. I have tried using Selector.select(timeout) and then checking the status of each channel, but they still show isConnected()=true.
    Thanks,
    Phil Blake

    Please don't cross post.
    http://forum.java.sun.com/thread.jsp?thread=184411&forum=4&message=587874

  • How to use Forms Default Database Connection in java class

    When a form based application is started, a connection is made with underlying database. This is the Default (Primay) Database Connection.
    The problem is I have some of my business logic implemented in a java class. In this class I have to make a another connection with the same database. What I want to do is to use the original Database Connection in the java class. In this I may avoid the overhead of reconnection.
    Could anyone pls guide me in this way...

    you can't share the forms connection. Sorry :(

Maybe you are looking for

  • Unable to read Properties file from Java code

    Hi, The directory structure of my application is as follows:- My App ++++++ src ++++++++com ++++++++++readProp.java ++++++++resource ++++++++++message.properties I am trying to read the file as follows:- <code> public Static final string FilePath="re

  • Virtualbox module won't compile?

    I upgraded Virtualbox from 4.0.10 to 4.0.12 and I am receiving an error when trying to compile the module by /etc/rc.d/vboxdrv setup. The contents of /var/log/vbox-install.log are : make KBUILD_VERBOSE=1 -C /lib/modules/2.6.39-ARCH/build SUBDIRS=/tmp

  • Icloud service is no longer available for your apple id

    icloud service is no longer available for your apple id What to do?

  • Function module for filename

    hi friends,               can any1 pls tell the name of the FM which asks where to download the file.               i am converting smartform to pdf and using FM convert_otf_2_pdf to convert.i want a pop-up window which will ask me where to store the

  • Cannot update photoshop or illustrator on PC through cloud

    I have been unable to update Photoshop CC2014, CS6 photoshop and illustrator as indicated by Cloud. Every time I try to update it says failure. I have a PC. Also my eraser is sluggish. I use a Wacom Tablet. The eraser often freezes up my computer.