Sending an object from client to server always on button press

What I need is to send an object from client to server but I need to make server wait until another object is sent. What I have is the JFrame where you put the wanted name and surname, then you create a User object with these details and on button press you send this object to the server. I just can't hold the connection because when I send the first object, server doesn't wait for another button click and throws EOFexception. Creating the while loop isn't helpfull as well because it keeps sending 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 this doesnt need to be via ssl, the problem would be the same using only http. Please anyone help me:)
Edited by: Vencicek on 7.5.2012 2:19
Edited by: EJP on 7/05/2012 19:53
Edited by: Vencicek on 7.5.2012 3:36

Current code fails because it's sending still the same entity again(using while loop)No it's not. You are creating a new User object every time around the loop.
which makes the system freezeWhich means that you are executing network code in the event thread. Don't do that, use a separate thread. At the moment you're doing all that sending inside the constructor for ClientFrame which is an even worse idea: you can never get out of there to the rest of your client program. This is a program design problem, not a networking problem.
and doesn't allow me to set new parameters of the new entityI do not understand.
I need to find a way to keep Server running even when the client doesn't send any data and wait until the client doesnt press the send button again to read a new object.That's exactly what happens. readObject() blocks until data is received.

Similar Messages

  • How to send multiple objects from Client to Server

    Hi
    I have a simple Client - Server architecture. I am trying to send 5 objects from Client to the Server which the server would operate on.
    In the past I've used PrintWriter to pass Strings from Client to Server but now when I am dealing with multiple Objects and PrintWriter not allowing sending of Arrays or ArrayList, how can I send these from the Client to the Server? What would be a good writer to use for this purpose?
    Thanks!

    Thanks, I am looking into ObjectOutputStream but from the API it appears I can only send 1 object at a time. I need to send 5 objects per transaction and then send the next group of 5 objects for another transaction.
    Could you clarify some more on how to put these objects together as a single Object perhaps?
    Thanks

  • Date converting to less one day while transferring from client to server

    Hi,
    I have very typical problem. My application is in java, we are using oralce 9ias. The problem when the server is running in german locale and client is running in english. We the date value is passed from client to server it is converting to one day less.
    i.e.
    If i want to search with records jan 02,2005,
    on server side if we print the value it is getting as jan 01,2005.
    Can anybody help me in solving the above problem.
    Its bit very urgent.
    Thanks in advance
    regards
    Kalyan

    well, i have had nightmares with this problem. here are the reason and soln:
    reason:
    in ur DB, u r using a field "Date" which does not include time information. Hence, any date will be taken at 00:00:00. If such a date is opened in some other timezone, which is ahead of the server timezone, the date differs by one. This is becoz java always considers the millisecond info encapsulated in the date, calendar.
    soln:
    Step 1:
    u must be able to get the "timeZoneOffset" from a calendar object. This timeZoneOffset will give the number of minutes/seconds/hours... by which the system is offset from GMT.
    Thus if u create a calendar in India, the timeZoneOffset will be 330. If you create the calendar in UK, it will be 0.
    To achieve this, we have made an object-UTCDate. This class encapsulates a Calendar. It has a function called "getTimeZoneOffset".
    Step 2:
    Once u get the timeZoneOffset, here is what u need to do in ur code. (assume that the timeZoneOffset is in minutes. the variable names will be self-explanatory)
    at the client side code:
    long timeInMillis = calendar.getTime().getTime() + (timeZoneOffsetOfTheCalendarReceivedFromServer * 60 * 1000 ) - (timeZoneOffsetOfClient * 60 * 60 )
    use timeInMillis to make a new Date Object and use this date object.
    at the server side code:
    long timeInMillis = calendar.getTime().getTime() + (timeZoneOffsetOfTheCalendarReceivedFromClient * 60 * 1000 ) - (timeZoneOffsetOfServer * 60 * 60 )
    hope this helps.
    regards

  • How to transfer passwords encrypted from client to server?

    Hello dear community,
    I have already some experience with programming and did a lot of web-software, but I never was facing the problem that passwords are transfered as plain text to the server when using a login-form.
    For my front-end, I use Java ServerFaces 2.0.
    I read a lot of hints like using a javascript based MD5 library and send the password as MD5 but this can be sniffed an decrypted easily.
    Do you have some hints to easily implement a secure transfer of values from client to server?
    best regards,
    Berni

    goose_fraba wrote:
    and how to do that? how to configure etc.?Server specific. Read your server's documentation.

  • Stream-in images from client to server,without running the transmit code

    Hello all,
    Im using JMF for my current project.Right now,I am trying to only recieve images from the client without the client transmitting it.That is I dont want the transmit code to run on the client.
    I should just be able to stream in the images from client to server, without running the transmit code on client.
    Can this be done?
    Thanks in advance

    suppigs wrote:
    Can I know more about this?Sure.
    <Side A>
    You'd just need to write an application that doesn't have a GUI (so, a console-based application) that listens on some pre-determined port for a message to start broadcasting. Maybe you'd send it the IP/PORT number to start broadcasting on. Once it receives that message, it'd start broadcasting the web cam to the IP/PORT number until it received a message to stop. Once it stops, it'll just go back to waiting for the next "start" signal.
    <Side B>
    On the other side, you'd write an application that sends the start messages, receives/displays the videos, and then sends the stop signal. This will have a GUI, and be your "control program" so to speak.
    Then, once of have both of those programs working...if you're using Linux, you're done. If you're using Windows, you'd need to modify the <Side A> program so that it can run as a Windows service.
    There are a lot of ways to do this, you can google it or look at the following link:
    [http://twit88.com/blog/2007/09/19/open-source-software-to-start-up-java-as-windows-serviceunix-daemon/]

  • Passing a object from browser to server

    How can i pass a java object from browser to server, can anybody help me in knowing this?
    Rajesh.

    You might need to clarify this. What exactly do you need to do? You can't pass anything from a browser except HTML, other than by attachment. If you have a Java object, then I assume that you are using JSP or something that supports Java, in which case you are already using server-side semantics.
    If however, you mean Javascript, that's a whole other problem, as it is client side only.
    Perhaps if you clarify what you are trying to do someone can give you a good answer.
    Regards,
    Paul

  • FLEX 2.0 and Flash Media Server 2.0 Unable to stream from client to server

    Hi All,
    I have been trying to put together a quick demo to stream
    and record audio from Client to Server. I get this error when
    trying to connect to FMS.
    ArgumentError: Error #2126: NetConnection object must be
    connected.
    at flash.net::NetStream/flash.net:NetStream::construct()
    at flash.net::NetStream$iinit()
    at Audio/toggle()
    at Audio/__submit_click()
    my Program fails at this line - ns = new NetStream(nc);
    Your help is greatly appreciated. Here is the MXML file
    Audio.mxml
    This file contains a simple start and stop button start and
    stop audio processing.
    This page is served from Apache Tomcat on host : demoserver1
    and port 8080
    Flash media server is also installed on the same host
    demoserver1.
    I did not do any additional config at FMS except creating an
    application called "DemoApp". All other settings are defaults.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    applicationComplete="startup()">
    <mx:Script>
    <![CDATA[
    import flash.net.NetConnection;
    import flash.net.NetStream;
    public var started:Boolean = false;
    public var nc:NetConnection;
    public var ns:NetStream;
    public var mp:Microphone;
    public function startup():void{
    lblMessage.text="Stopped";
    public function toggle():void{
    if (started==false){
    submit.label="Stop";
    started=true;
    lblMessage.text="Started";
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS,
    netStatusHandler);
    nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
    securityErrorHandler);
    nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
    nc.connect("rtmp://demoserver1/DemoApp");
    ns = new NetStream(nc);
    ns.addEventListener(NetStatusEvent.NET_STATUS,
    netStatusHandler);
    mp = Microphone.getMicrophone(0);
    ns.attachAudio(mp);
    ns.publish("sample1", "record");
    else{
    started=false;
    submit.label="Start";
    lblMessage.text="Stopped";
    ns.close();
    nc.close();
    private function netStatusHandler(event:NetStatusEvent):void
    switch (event.info.code) {
    case "NetConnection.Connect.Success":
    trace(" connection success : " );
    break;
    case "NetStream.Play.StreamNotFound":
    trace("Stream not found: " );
    break;
    private function
    securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
    ]]>
    </mx:Script>
    <mx:Canvas xmlns:mx="
    http://www.adobe.com/2006/mxml"
    width="400"
    height="300">
    <mx:HBox left="19" right="0" height="100" top="30">
    <mx:Label text="Label" id="lblMessage" width="150"/>
    <mx:Button label="Start" click="toggle()" id="submit"/>
    </mx:HBox>
    </mx:Canvas>
    </mx:Application>

    Hi,
    Are you trying to make an air app or a web application (flash) for streaming? You may want to check out the osmf framework to help you write a player for mobile platform. Check out http://www.opensourcemediaframework.com/ for more info on how you can write streaming video players using this framework. There are some good tutorials there and also you may post on the forum to get your specific queries solved.
    Thanks,
    Abhishek

  • Send iCloud email from alternative smtp server?

    How do I send iCloud email from alternative smtp server? The setting is 'greyed out' on my iPhone so I cannot tell iCloud to use another server.
    The reason is so I can have my outgoing email appear from my own domain email address rather than my me.com address. Mobileme would allow this - and Mail on the Mac does allow it, but the iPhone under iOS 5 seems not to allow it....
    Any ideas?

    I have spent about 4-6 hours working directly with folks from Tim Cooke's office, various support levels, and through them their engineers.
    As much as I tried to convince them their logic is flawed, the engineers for iCloud come back and say this is expected behavior because somehow it helps secure iCloud from being a spam source. The fine and helpful gentleman from Cooke's office now understands how it is a MobileMail.app client issue, having nothing to do with iCloud servers (because we are in fact trying to bypass their servers) still totes the "it's expected behavior" line from the server engineers.
    I have implored him to follow up with the iOS MobileMail app programmers and not the iCloud programmers. I am hopeful he will. Until then you have to choose between having iCloud push and losing your online identity, or losing push email and keeping your preferred address.
    Fun to try: turn off all smtp servers. Send email. Gets stuck in outbox. Turn on your preferred smtp server. That one email will use your preferred alternate address, but subsequent ones revert back to the old .me.com smtp servers. Personally I believe this points to a client programming error more than reinstating a preferred behavior. Aggravating!
    I spend $500 on a new phone. Google takes away my exchange client ability and apple makes me choose push email vs outgoing email address.

  • How to Serialize a file path from client to server?

    I am using serializing concepts in java. I am stuck, that how can i send only file path from client to server?

    Um, ill take a wild guess and say that youre trying to
    access a file on another computer using that path?
    That wont work.
    What could the other computer possible do
    with that path unless both computers are networked to a
    common drive, or if they are networked to each other in a way
    where the root in the file path would point to the same place
    on either computer?

  • Converting date value one day less while transfering from client to server

    Hi,
    I have very typical problem. My application is in java, we are using oralce 9ias. The problem when the server is running in german locale and client is running in english. We the date value is passed from client to server it is converting to one day less.
    i.e.
    If i want to search with records jan 02,2005,
    on server side if we print the value it is getting as jan 01,2005.
    Can anybody help me in solving the above problem.
    Its bit very urgent.
    Thanks in advance
    regards
    Kalyan

    // to get  current time in Germany
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Germany"));
        int hour12 = cal.get(Calendar.HOUR);
        int minutes = cal.get(Calendar.MINUTE);    
        int seconds = cal.get(Calendar.SECOND); 
        boolean am = cal.get(Calendar.AM_PM) == Calendar.AM;
        //I think all you need to do is to set the timezone to the current, so that when the
    //server at some other timezone gets this date it knows that this date belongs to
    //different timezone and gets converted automatically according to the server
    //timezone settings.
        // Set the current local timezone
        cal.setTimeZone(TimeZone.getDefault());
        int hour24 = cal.get(Calendar.HOUR);
      Hope this answers your question. Good luck.
    -Sreekanth varidhireddy

  • How to deploy Forms, Reports and Menu from Client to Server machine

    Dear Experts,
    I have one requirement to deploy the Forms, Reports and Menu from client machine to server machine.
    Deployment involves the following steps :
    1. Firstly we have to search the selected file in a folder where the .fmx is present ( in Server machine) and take the back up of the the existing file in the server (Source and destination paths will be available).
         Ex. If the existing FMB name is TEST.fmx then the backup file should be TEST_sysdate.fmx.
    2. Secondly we have to transfer the file from the client folder (or from another folder of the same server) to the server folder where the back up exists.
    Please help me to search/rename/copy/replace the _.fmx/.rdf/.rep/.mmx_ files from client to server.
    We are using
    9i Database.
    10g Forms and reports.
    SQL Developer tool.
    OS is Windows (Client and Server).
    Help me out to attach a file of front end screen which we are planning to develop. It will give a clear picture on this requirement.
    Thanks :)
    Edited by: 941175 on Jun 17, 2012 9:09 AM
    Edited by: 941175 on Jun 17, 2012 9:12 AM
    Edited by: 941175 on Jun 17, 2012 9:14 AM

    941175
    Welcome to the forum. Please take a while to go through the FAQ to be found to the top right of the page.
    Your issue is more to do with batch files rather than Forms. The only relation with Forms, as I see it, is that you will be using HOST/CLIENT_HOST to start a batch file with the file name to be deployed as a parameter passed to it.
    You need to rewrite either a CMD batch file or a Powershell script to achieve what have set out to do.
    For CMD batch files look up http://www.robvanderwoude.com/battech.php , or any of the other excellent resources available on the internet.
    Regards,

  • Transfer file from client to server using http

    HI friends,
    I want to transfer files from client to server...I tried that with the help of socket and rmi..........
    But Http is only the best mechanism for my application..........
    Without using servlets, how to transfer files with the help of http.....
    Any help would be appreciated.......

    Google is your friend, and appearently www.jguru.com also:
    http://www.jguru.com/faq/view.jsp?EID=160

  • Accessing an object from a different server

    Hi,
    I am making a program that will access an object from a different server.
    I have a program that when I run calls a jsp page running on Server A which in turn should request an object A from Server B.
    I am relatively new to Java and jsp. What would my best course of action be.
    Thanks in advance,
    Brian

    Or RMI?OK, sounds good, I will look up some RMi on the site.
    Thanks, will prob have more questions for you later.

  • Urgent - Upload a file from Client to Server.

    Need to load a file from the client machine to the Server running 9iAS Rel. 1 on a HP Unix Machine.
    We are using Forms 6i. We have looked into the File Upload Utility demo code provided with Forms 6i - but have been unsuccessful in reusing it. PLS HELP

    Duplicate post.
    Upload a file from client to server by forms in E-Bussiness Suite R12
    Re: Upload a file from client to server by forms in E-Bussiness Suite R12.

  • Problem while sending seriailized  object from applet to servlet

    Hi I m having Object communication between Applet and Servlet.
    I m getting error stack trace as
    java.io.EOFException
         at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
         at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
         at java.io.ObjectInputStream.<init>(Unknown Source)
         at com.chat.client.ObjectClient.write(ObjectClient.java:56)
    at the line
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    thanks in advance
    Ravi
    the whole code is as follows....
    public Serializable write(Serializable obj) throws IOException,ClassNotFoundException{
              URLConnection conn = serverURL.openConnection();
              conn.setDoOutput(true);
              conn.setDoInput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "java-internal/"+obj.getClass().getName());
              conn.connect();
              ObjectOutputStream oos= null;
              try{
              oos = new ObjectOutputStream(
                   conn.getOutputStream());
                        oos.writeObject(obj);
                   catch(Exception ee){
                                       ee.printStackTrace();
                   finally{
                        if(oos!=null){
                             oos.flush();
                             oos.close();
                        return the reponse to the client
                   ObjectInputStream ois=null;
                   try{
    \\this is the line where i m getting the error               
    ois = new ObjectInputStream(conn.getInputStream());
                             return (Serializable)ois.readObject();
                        catch(Exception ee){
                                            System.out.println("Error in Object Client inputstream ");
                                            ee.printStackTrace();
                                            return null;
                        finally{
                             if(ois!=null){
                                  ois.close();

    Did anyone find a fix to this problem. I am having a similiar problem. Sometimes I receive an EOFException and othertimes I don't. When I do receive an EOFException I check for available() in the stream and it appears 0 bytes were sent to the Servlet from the Applet.
    I am always open to produce this problem when I use File->New in IE my applet loads on the new page.. and then I navigate to a JSP sitting on the same application server. When I go to the Applet on the initial page and try to send an object to the server I get an EOFException. No idea!

Maybe you are looking for