Send an object from client to server always a button

What I need is to send an object from client to server, but I need server wait for another object is sent. What I have, it's the JFrame where you put the name and surname, then you create a user with these details object and you press the button send this object on the server. Just, I can't keep the connection because when I send the first object, the server does not wait for another button click and survey EOFexception. Creating the while loop is useful both because it continues to send the same object again and again. The code is here
public class ClientFrame extends JFrame {

    private JButton btnSend;
    private JTextField txfName;
    private JTextField txfSurname;

    public ClientFrame() {
        this.setTitle(".. ");

        Container con = this.getContentPane();
        con.setLayout(new BorderLayout());

        txfName = new JTextField("name");
        txfSurname = new JTextField("surname");

        btnSend = new JButton(new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                SSLSocketFactory f =
                        (SSLSocketFactory) SSLSocketFactory.getDefault();
                try {
                    SSLSocket c =
                            (SSLSocket) f.createSocket("localhost", 8888);

                    c.startHandshake();

                    OutputStream os = c.getOutputStream();
                    ObjectOutputStream oos = new ObjectOutputStream(os);
                    InputStream is = c.getInputStream();
                    ObjectInputStream ois = new ObjectInputStream(is);

                    
                    boolean done = false;
                    while (!done) {
                        String first = txfName.getText();
                        String last = txfSurname.getText();
                        User u = new User();

                        u.setFirstName(first);
                        u.setLastName(last);
                        oos.reset();
                        oos.writeObject(u);

                        String str = (String) ois.readObject();
                        if (str.equals("rcvdOK")) {
                            System.out.println("received on the server side");
                        } else if (str.equals("ERROR")) {
                            System.out.println("ERROR");
                        }
                    }




                    //oos.writeObject(confirmString);

                    oos.close();
                    os.close();
                    c.close();

                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(ClientFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    System.err.println(ex.toString());
                }
            }
        });
        btnSend.setText("send object");
        con.add(btnSend, BorderLayout.PAGE_START);
        con.add(txfName, BorderLayout.CENTER);
        con.add(txfSurname, BorderLayout.PAGE_END);
        this.pack();
        setSize(200, 150);
        setVisible(true);
    }
}

public class TestServer {

    public static void main(String[] args) {
        
        try {
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(new FileInputStream(ksName), ksPass);
            KeyManagerFactory kmf =
                    KeyManagerFactory.getInstance("SunX509");
            kmf.init(ks, ctPass);
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(kmf.getKeyManagers(), null, null);
            SSLServerSocketFactory ssf = sc.getServerSocketFactory();
            SSLServerSocket s = (SSLServerSocket) ssf.createServerSocket(8888);
            printServerSocketInfo(s);
            SSLSocket c = (SSLSocket) s.accept();
 

            InputStream is = c.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            OutputStream os = c.getOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(os);
            boolean done = false;
            User u;
            
              while(!done){
                  
                
                u = (User) ois.readObject();
                String confirmString = "rcvdOK";
                String errorString = "ERROR";
                if (u != null) {
                    System.out.println(u.getFirstName() + " " + u.getLastName());
                    oos.writeObject(confirmString);
                } else if (u == null) {
                    oos.writeObject(errorString);
                }
                
                
            
            }

            is.close();
            s.close();
            c.close();

        } catch (Exception e) {
            
                System.err.println(e.toString());
            
            
        }
    }

   
}
Thanks for any help, btw, it does not need to be over ssl, the problem would be the same as using the http protocol. Please someone help me :)

Published by: Vencicek on 7.5.2012 02:19

Published by: EJP 05/07/2012 19:53

Published by: Vencicek on 7.5.2012 03:36

I responded to that. Do not call the methods of networking in the thread of events, or in a constructor.

Tags: Java

Similar Questions

  • How to send the email from the content server?

    How to send the email from the content server? Is this enough to configure the SMTP server with the content server oracle? I want to send a mail generated both system admin system and author of the content when a content is expired. Please suggest how to enable e-mail functionality. Please suggest how the mail will be sent both SYSADMIN and author.

    Thank you

    In particular, this can be achieved by configuring - see EnableExpirationNotifier

  • Download files from client to server

    Hey guys,.

    no idea how can I transfer a file from a client computer to the server, I tried the webutil but I have problems with regard the use with ACE as shown


    File transfer is slow :(

    any help?

    Below a is a box of Solaris windows files to a windows FTP server.
    Create a batch based on this file and test command/shell line

    #[email protected] FTP
    FTP - n - v alexyscorp.com Xa892pt app user
    bin
    LCD display ${BACKUP_DIR}
    CD /HOTBACKUP
    mput arch_$ {FILEDATE} .tar
    ECHO $(date)
    close
    !

    Rajesh Alex

  • Send the email from the form and no attachment button

    I use Acrobat 9 Pro and would have created several "Send by E-mail" buttons on Forms.  I now have the need to simply send a specific e-mail message when the user clicks on the button, but I do not want to attach the PDF file.  I use Outlook as my email client.  How can I go about it?

    Thanks in advance.

    As the button MouseUp event, remove the current measure and add a Run

    JavaScript Action, with the following code:

    app.mailMsg ();

    Of course, you can replace the recipient's address, the subject and the message with

    your own.

  • LabVIEW TCP/IP Client and server, I need to send commands and receive comments side server from the client regarding the command sent.

    Hi all

    I can configure my two PCs, one as a client and a server very well. I am able to send commands from the server to the client. However, I am trying to determine how I can get feedback from the client to the server that something has changed, or a CQI that the command has been received. How I can do this in LabVIEW with the box to TCP/IP tools, or is there a better way to do it?

    Thanks for your help!

    Best regards

    -Gmac

    Once the connection is established, TCP does not care which end is the 'server' and the 'customer '. Data can be sent in both directions using the same read and write functions. So, if you are already able to send data to the client and read on the server, you should be able to do the same to send data from the server to the client, using the same TCP connection.

    If this is not clear, please your postal code so that we can provide more specific advice.

  • Hyperion 8.3-> Server [2009] Impossible to recover the OCÉ object from the repository

    Hello Experts,

    Need help. We have an old version of Hyperion 8.3. We moved our database server where we installed our database of the Hype. At one point, we run our report from the portal, we will the error

    Server [2009]: impossible to recover repository object ECA

    Our DEV and UAT have been down for weeks now because of this problem. Anyone can share or have a few entries for us to solve this problem.

    Your response is much appreciated.

    Thank you
    Manny

    Here's what doc Oracle support - http://support.oracle.com

    Applies to:
    
    Hyperion BI+ - Version 9.3.1.0.00 and later
    Information in this document applies to any platform.
    ***Checked for relevance on 29-May-2013***
    Symptoms
    
    "Unable to retrieve OCE object from repository" error when opening BQYs via Interactive Reporting Web Client.
    
    Cause
    
    The effdate.dat file is missing in Hyperion/BIPlus/data/ES1_hostname
    
    This message is displayed many times in the logs: "com.sqribe.transformer.PublishLogEffectiveDateStorage.getEffectiveDate: Error while reading "/Hyperion/BIPlus/data/ES1_hostname/effdate.dat". null"
    
    Solution
    
    Copy effdate.dat from /Hyperion/BIPlus/data/RM1_hostname to /Hyperion/BIPlus/data/ES1_hostname and restart System 9.
    

    Once again, I'm not sure if this applies to you or not, just trying to help.

    Thank you
    hyperionEPM
    Please check the answers as useful or correct for others to find them easily.

  • Client DHCP is unable to get a valid IP address from the DHCP server.

    Client DHCP is unable to get a valid IP address from the DHCP server. I have a home edition of Windows XP attempts to connect to my router wirelessly with wireless or wired connection but I get an error in Event Viewer with the discription DHCP 1007 error message. From what I researched, I discovered that the DHCP service depends on the AFD, TCP/IP and NetBT services. All these services are correctly place and worked very well (even the DHCP service is running without error) but every time I try to release/renew my IP address I receive than DHCP warning in the case where the viewer and I just cannot get a valid IP address of the server (router) I also have one of these verizon wireless G3 usb adapters and it works fine. I also have a good ping back when I try to do a ping localhost (for the closure) I also tried the preinstallation of uninstalled drivers from the adapter/s and nothing works. The only entrees in the registry for DHCP error are also AFD, NetBT and TCP/IP nothing else there, also all the files in the/system32/drivers afd.sys netbt.sys and tcpip.sys in addition to solve the problem, I'll mention that I installed and reinstalled Northon earlier, I do not remember if the problem appears before or after that. I receive also any error or warning in the security log or at least I don't know how to read: P

    Thanks in advance

    Thanks for the information.

    I hope you know that it is risky to connect the laptop to the Internet with no firewall and no antivirus... If this laptop is already connected to the Internet in this State, he is perhaps already infected.

    You said you know the router works because the other computers can connect successfully to it.  You should check the configuration of the router to make sure that it is not configured to limit the number of IP address it supplies, and (b) it is not configured to filter users by MAC address.

    When this laptop is connected by Ethernet, even if he gets the IP address of 169.254.x.y, can you ping the router?  Find the IP address of the router on any computer connected to it by running the ipconfig command in a command prompt window.  The "default gateway" is the IP address of the router.  Run the ping command in the command prompt window as well.

    If the ping is successful, it is possible that you might be able to use an IP address in the correct range for an Ethernet cable (but I doubt that it works for the wireless).

    It is very difficult to cite anything in this forum.  If you click on the link "Reply citing", all of the message to which you are replying is quoted.  You can copy the citation and delete parts of it, but it is not very user friendly.

  • How to get Windows Live Mail 2011 to remove emails from my hotmail server account once they have been synchronized with the WML client. ?

    How to fix WLM 2011 to remove emails from my hotmail server account once they have been synchronized with the WML client. ? I've seen several references in forums to an option that is located on the Advanced tab in the menu Options/Email accounts/properties, but I don't have an option in the Advanced tab in this menu. Is there another way to do it. ? I tried to do this manually, but when I manually delete a message in my Hotmail account it also deletes the message on the client when it synchronizes. I would like to have my messages stored on my customer only and not on the server. Is there a way to do this. ?

    View all Windows Live and Hotmail questions in the appropriate forum found here:
    http://windowslivehelp.com/

  • PHP form script is missing from the web server or PHP is not properly configured on your web hosting provider. Help - I get this message on my site when the form is filled out and you press send... Check if the form PHP script has been downloaded correctl

    PHP form script is missing from the web server or PHP is not properly configured on your web hosting provider. Help - I get this message on my site when the form is filled out and you press send... Check if the form PHP script has been downloaded correctly, contact your host about the configuration of PHP.

    Hi Graham,

    If you, please add your site to this link ( http://my-site.com/scripts/form_check.php ) and make sure that all green checkmarks are appearing. If they don't, let us know what errors you seem to receive and include the link to your site.

    In addition, check out this guide on the forums of Muse troubleshooting: Troubleshooting Muse form used on the servers of third party Widgets

    I hope this helps!

    Emily

  • Download file from the database server, through application server.

    Nice day

    I use Jdeveloper 11.1.2.3.0.

    I have a requirement to download a file that already exists on the database server Directory. Now my current scenario is that user is connected to the application server, and the user has no direct access to the database server.  I drew a diagram of my requirement as:


    DownloadFile.png


    I get a way to do this. Please suggest.


    Best regards,

    Julien

    The session does not expire if you are streaming data from the application to the client. However, you will need to manage the data sent over the network, because it can make the very slow network if you send this amount of data at high speeds on the network and then to the customer. This connection between client and server is the biggest problem, because bandwidth is usually small. Think about downloading software by one side oracle (for example 1 GB), this takes time and is prone to errors.

    We did something similar by transferring the data from the database (in our case, it has been stored in a BLOB) on a dedicated server with a server web apache on it. Then, we send a link to the client, which then uses the link to get the special file server data.

    The advantage is that you don't have to code the transfer of huge files in the application of the adf but can already use ready to use of software (balancing bandwidth and the recovery of a broken download).

    Timo

  • I can't download contact sheets to the site ftp continues to receive "an error occurred sending the file: access denied" it used 100% of the time, then about 70% not at all, having to send boards contact my clients. Using Version 6 on Imac.

    I can't download contact sheets to the site ftp continues to receive "an error occurred sending the file: access denied" it used 100% of the time, then about 70% not at all, having to send boards contact my clients. Using Version 6 on Imac. Any suggestions on how to make it work again?

    Hi Dayg,

    Please check your FTP settings in Lightroom.

    Are you able to connect and download using another FTP Client?

    Also try the steps below: -.

    1. from the Web in Lightroom module, click export instead of loading.

    2. save the Gallery to a location that you can find easily (like your desktop).

    3. manually copy the Gallery of his location to save to your FTP server.

    Let us know if that helps.

    Kind regards

    Assani

  • How do I send the email from the Application Web ADF

    Hello

    JDeveloper Version: 11.1.1.5.0

    I develop an ADF Web Application that contains the user interface pages developed using JSF. I provide a two or three page button which, when clicked will be posting current pdf page content or documents to a mail id.
    I run my Web ADF Application on Weblogic Server built-in by default.

    For the mail merge feature, I try the following code in my grain of support:


    public String mail() {}
    Add the code in the event here...
    Identification of the recipient should be mentioned.
    String to = "[email protected]";

    Email of the sender identification should be mentioned
    String from = "[email protected]";

    Assuming that you send e-mail from localhost
    String host = "localhost";

    Get system properties
    Properties properties = System.getProperties ();

    The mail Server Setup
    properties.setProperty ("mail.smtp.host", host);

    try {}
    Retrieve the default Session object.
    Session;
    session = (Session) Session.getDefaultInstance (properties, null);
    Create a default MimeMessage object.
    MimeMessage message = new MimeMessage (session);

    Set of: header field in the header.
    message.setFrom (new InternetAddress (from));

    Value: header field in the header.
    message.addRecipient (Message.RecipientType.TO,
    new InternetAddress (to));

    Set object: header field
    message.setSubject ("this is the subject line!");

    Now define the message itself
    message.setText ("this is a real message");

    Send message
    Transport t = session.getTransport ("smtp");
    t.Connect ();
    Address toAddr = new InternetAddress [] [1];
    toAddr [0] = new InternetAddress (to);
    t.sendMessage (message, toAddr);
    t.Close ();
    Transport.Send (message);
    System.out.println ("sent message successfully...");
    } catch (MessagingException mex) {}
    mex.printStackTrace ();
    }

    Returns a null value.
    }

    Note: [email protected] is replaced by gmail valid id in real code.

    When I try to call the method mail() above since the command button in my page, it is to launch the exception below:


    javax.mail.MessagingException: Exception reading response;
    nested exception is:
    java.net.SocketException: connection reset
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1611)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
    at javax.mail.Service.connect(Service.java:288)
    at javax.mail.Service.connect(Service.java:169)
    at javax.mail.Service.connect(Service.java:118)
    at xxxxxxxxx.ui.SendMail.mail(SendMail.java:102)


    Please let me know if the code position of java at the above address is fine or if I make changes in my WebLogic Server to allow installation of electronic mail

    I use Apache Commons email (http://commons.apache.org/email/) to make something similar. It is easy and comes with samples, and it works!

    Timo

  • problem when call one side Committee client-side Server

    Hello world! I have a problem when I call a side Committee client-side server.

    Here's the code. When the swf file is connected to the FMS (the connection is successful) I use this application.user_so.send ("enterContestGroup"); to call the Committee client side. You can see that in the client side, I've defined the Committee 'enterContestGroup '. However, the fact is that it does not call that Committee. Can someone tell me what is the error?

    Thanks for any help!

    This is the code on the server side:

    application.onAppStart = function()
    {
    application.user_so = SharedObject.get ("user_so", false);
    application.nextId = 0;
    }
    application.onConnect = function (newClient)
    {
    application.acceptConnection (newClient);
    application.user_so. Send ("enterContestGroup");
    }

    This is the code on the client side:

    var nc:NetConnection = new NetConnection();
    var url: String = "rtmp://localhost:1935 / testapp";
    var user_so:SharedObject = new SharedObject();

    NC. Connect (URL);

    nc.onStatus = function (info)
    {
    If (info.code is "NetConnection.Connect.Success")
    {
    trace ("Success!");

    }
    on the other
    {
    trace (info.code)
    }
    }
    user_so = SharedObject.getRemote ("user_so", nc.uri, false);
    user_so. Connect (NC);

    user_so.enterContestGroup = function (uname, uimg, uid, cid)
    {
    trace ("do something about enterRoom")
    }

    Hello

    In fact, you can use broadcastMsg API to deliver the object to the customers.

    Here is an example of its use.

    Server-side:

    var obj = new Object();
    application.onConnect = {function (customer)}

    obj. Prop1 = "1";
    obj. Prop2 = '2 ';
    application.acceptConnection (client);
    Broadcast (obj);
    }

    var broadcast = {function (obj.)}
    application.broadcastMsg ("m1", obj);
    }

    (AS2) client-side

    var nc = new NetConnection();
    nc.onStatus = {function (info)}
    trace (info.code);
    }

    NC. M1 = {function (obj.)}
    trace (obj. Prop1);
    trace (obj. Prop2);
    }

    NC. Connect ("rtmp://localhost/test");

    Let me know if experience you problems with this.

    Thank you

    Abhishek

  • Mine is Yahoo where POP is used. Tuberculosis is IMAP. I can receive and send emails, but when doing action on tuberculosis (Del or send) any reflection on the primary server

    Hello
    My e-mail address is Yahoo and Yahoo by default user POPs.
    I understood from your help file synchronization is only compatible with the IMAP e-mail provider
    I can receive and send emails from TB, but during action on tuberculosis (Del or send) any reflection on the primary server, even when doing the action on the main server (Del or send), no change on tuberculosis

    help from yahoo I managed to find the Setup for IMAP, but could not apply them on TB, TB already have Yahoo as POP in the configuration list
    Please your help on this

    Best regards
    Mohamad

    You cannot convert an existing account, but you can set up your Yahoo as IMAP account in parallel to the existing POP account. See
    http://KB.mozillazine.org/Convert_a_POP_account_to_a_IMAP_account

  • How can I that emails from a particular server?

    Details: I get emails from people who sell Viagra etc, and other offering *. I block these emails, but spammers change their e-mail address, so I would like to know how I can identify what 'server' sends these messages and block this server. The community does have ideas? signed is not interested by your *.

    Hi, Bason2,

    Use SpamCop or learn to trace the IP address of the spammer.  From there on, report it to their ISP provider.

    What Email Headers can tell you about the origin of Spam

    http://email.about.com/cs/spamgeneral/a/spam_headers.htm

Maybe you are looking for

  • Pavilion 15 - ab219tx: Internet slows down after connecting the mobile to WiFi.

    Previously, I had a problem where internet connection slowed down painfully when cell phone charges. I tried to reset the power settings. Now I can connect to the laptop... However, now the problem is that if connect you to WiFi via the laptop, regar

  • temperatures Y50-70

    Hello everyone, I got my lenovo y50-70 for a few days and I used it a lot lately. After a while I noticed that my temperature rose significantly. What worries me the most, it is my slow time symmetric mode (energy Manager) are around 50-60 used to be

  • How can I get the question mark to come upcorrectly and not as a THURSDAY

    When I change to us the question mark I get this E - How do I get this turned off -

  • Replace hard drive on HP G72 information

    Our HP G72-B27CL family has a failed hard drive and continues to give the following message "hard drive error (301).  After some reading online, I am aware that this means the hard drive turns off finally completely and that it should be replaced.  T

  • color printer problem

    Cyan does not; Yellow barely comes out when printing.  Tried all three levels of cleaning of the printheads with no luck. Print report prints black (three shades of black & gray); Pink (six shades of pink); shows barely any yellow; no blue. Another p