Why the socket is closing

Hi ,
I would like to send the MimeMessage object via socket connection. To do do that i have written the following code fragment
Socket s = new Socket("localhost",3200);
OutputStream os = s.getOutputStream();
MimeMessage mimemessage
//some code to create MimeMessage
mimemessage.writeTo(os);
os.close() // this is important step
In this code fragment if i didnt close the output stream the message is not being delivered to the server side. But when i close the output stream it is closing the socket connection with the stream connection.
What i neeed is i will be sending mimemessage objects via socke asynchronously. For that purpose i would like to keep the outputstream of the socket keep opent always. But how can i send the mimemessage object via socket without closing the stream.
I tried os.flush() also. but no result.
Please help me.
thanks in advance,
Sridhar reddy .R

I am not using any server n server is simple java server socket.
here is the code for server
public class MyServer extends Thread
public static void main(String[] a)
ServerSocket sss= newServerSocket(3200);
while(true)
Socket s = ss.accept();
new MyServer(s).start();
public MyServer(Socket socket)
this.socket = socket;
is = socket.getInputStream();
public void run()
while(true)
Properties prop = System.getProperties();
Session session = Session.getInstance(prop, null);
MimeMessage mimemessage = new MimeMessage(session,objectStream);
// do some operations on this message

Similar Messages

  • Why the ringing voltage closely 0v for VIC3-2FXS/DID port?

    Initially, I have tested every port of FXS module on ISR with an analog phone. There
    was ringing tone and I was able to communicate to other as normal. The second
    test involved measuring the ringing voltage on the same ports by using a pair cable and multimeter. The
    'idle voltage' measured was around 44V and when there was an incoming call, the measured 'ringing
    voltage' was close to 0V.
    So why the ringing voltage is drop to 0V?
    Please advice.

    You cannot measure ringing voltage with a common multimeter. Read why:
    http://www.sandman.com/ringvoltbul.html

  • Sockets not closing

    I'm doing some simple socket programming but I'm having trouble getting my sockets to close. I tell them to close but they don't seem to be recognized as closed.
    Here is where I get create my socket:
    {code
    Socket connectionSocket = myWelcomeSocket.accept();
    ChatWindow window = new ChatWindow(connectionSocket);
    (new Thread(new SendToClient(connectionSocket,window))).start();
    (new Thread(new ReceiveFromClient(connectionSocket,window))).start();
    so all of these objects know about the connection
    Here's SendToClients run method:public SendToClient(Socket socket, ChatWindow window)
    try
    myConnectionSocket = socket;
    myOutToClient = new DataOutputStream(socket.getOutputStream());
    myWindow = window;
    catch (IOException e)
    // TODO Auto-generated catch block
    e.printStackTrace();
    public void run()
    while(myConnectionSocket.isConnected())
    //do some stuff
    In ChatWindow I can close the window and I want this to close the connection:public ChatWindow(Socket connectionSocket)
    myConnection = connectionSocket;
    this.addWindowListener(new WindowAdapter()
    public void windowClosing (WindowEvent e)
    try
    myConnection.close();
    catch (IOException e1)
    // TODO Auto-generated catch block
    e1.printStackTrace();
    //other stuff
    When I close the window, it should close the connection but other classes still see the connection as connected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Yeah this is a TCP thing. If the connection is closed remotely on a non-blocking channel its key will repeatedly be flagged as 'readable' but reading will not return -1 but instead will return 0.
    You could set a counter and assume that a read operation of 0 bytes for x number of times is a closed socket. That should be reasonably safe depending on the application.
    Unfortunately the only real way to know if a socket is closed is to write to it. This will throw an IOException. Ugly but accurate 99.99% of the time. (Never be 100% positive :)
    What I do is write OOB data to the socket to test it. That way even if the other end is still connected and I can't send it random data the socket will silently discard the OOB data. That is unless you have changed the default setting to inline urgent data, in which case the OOB data will be read just like regular data. And having the OOB data discarded down the line doesn't matter, it's the local test we need.
    I simply use something like this:
         * Check if the socket is closed. Ugly but effective.
         * @return True if the socket is closed, false otherwise.
            public boolean isClosed()
                try
                     *NOTE: Using this because normally OOB urgent
                     * data is silently discarded by the socket
                     * however if socket.setOOBInline(true) is used this
                     * won't work as expected.
              chan.socket().sendUrgentData(1);
              return false;
                catch(IOException ex)
                    return true;          
            }

  • How the client to detect  the server has closed the socket?

    if the server closed the socket by an unnormal way, for example, closing the socket compulsively. Then the client will show the "IOException:java.net.SocketException: Connection reset" message,
    how the client to avoid such an error message to the user/customer, I mean , what the client can deal with such a message?
    where to put the dealing code?
    try{ int receivedLength=in.read(receivedBytes);
    }catch(SocketException e){
    // put the code here? }
    catch(IOException e){
    }

    Do you know how to prove it---"a socket read should
    always always always have a timeout";As ejp said (IMHO ...) it's his opinion and doesn't need proof. I respect his opinion, but I often write code that doesn't set this.
    Instead I use 2 threads per connection, and don't care if the read thread goes to sleep, since I can still write. If you only have one thread per connection, you better ensure that the read will end in a relatively short amount of time, even if your partner decides it's time to go for lunch.
    how the length of this timeout will be? That is a business decision, it all depends on the expected time between received messages and is application dependent.
    is it a field of the socket?If you are using blocking mode sockets you set this with setSoTimeout. If you are using non blocking mode NIO you specify it on the select call, although the soTimeout should also work there, although I've never tried that.

  • Socket.getOutputStream must precede the socket.getInputStream?!? Why?

    This is server code.......
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class DateServer extends Thread {
       private ServerSocket dateServer;
       public static void main(String argv[]) throws Exception {
         new DateServer();
       public DateServer() throws Exception {
         dateServer = new ServerSocket(3000);
         System.out.println("Server listening on port 3000.");
         this.start();
       public void run() {
         while(true) {
           try {
            System.out.println("Waiting for connections.");
            Socket client = dateServer.accept();
            System.out.println("Accepted a connection from: "+
    client.getInetAddress());
            Connect c = new Connect(client);
           } catch(Exception e) {}
    class Connect extends Thread {
       private Socket client = null;
       private ObjectInputStream ois = null;
       private ObjectOutputStream oos = null;
       public Connect() {}
       public Connect(Socket clientSocket) {
         client = clientSocket;
         try {
          ois = new ObjectInputStream(client.getInputStream());
          oos = new ObjectOutputStream(client.getOutputStream());
         } catch(Exception e1) {
             try {
                client.close();
             }catch(Exception e) {
               System.out.println(e.getMessage());
             return;
         this.start();
       public void run() {
          try {
             oos.writeObject(new Date());
             oos.flush();
             // close streams and connections
             ois.close();
             oos.close();
             client.close();
          } catch(Exception e) {}
    }This is client code....
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class DateClient {
       public static void main(String argv[]) {
          ObjectOutputStream oos = null;
          ObjectInputStream ois = null;
          Socket socket = null;
          Date date = null;
          try {
            // open a socket connection
            socket = new Socket("127.0.0.1", 3000);
            // open I/O streams for objects
            oos = new ObjectOutputStream(socket.getOutputStream());
            ois = new ObjectInputStream(socket.getInputStream());
              System.out.println( "BAU!" );
            // read an object from the server
            date = (Date) ois.readObject();
            System.out.print("The date is: " + date);
            oos.close();
            ois.close();
          } catch(Exception e) {
            System.out.println(e.getMessage());
    }OK.
    Those work just fine. Now if you put socket.getInputStream before the socket.getOutputStream then it hangs!
    Any ideea why this happens and why is not documented... I just lost tow hour tring to figure it out why my program just hangs. After I have set the order as In the example above all works....
    If anyone knows why please share your knowledge...
    Hope this will save others a lot of lost time.

    The order matters because the ObjectOutputStream constructor writes a stream header and the ObjectInputStream constructor reads the header.
    If both ends of the conversation do "new ObjectInputStream()" they both forever wait for the other end to write the header. So one end needs to create the output stream first and the input stream second, and the other end in the other order (or do them in different threads.)
    If it isn't documented it should be IMHO. Re-check the javadocs; if it isn't mentioned file a bug report to Sun. There is a bug parade link on http://java.sun.com/ somewhere.

  • Detecting When a Non-Blocking Socket Is Closed by the Remote Host

    Hi,
    Using NIO non blocked sockets how do I detect when a Non-Blocking Socket Is Closed by the Remote Host?
    What I have read is:
    The only way to detect that the remote host has closed the connection is to attempt to read or write from the connection. If the remote host properly closed the connection, read() will return -1. If the connection was not terminated normally, read() and write() will throw an exception.
    I have written a server test program using NIO and an applet connecting to the server program via sockets.
    When I after a successful connection shuts down the browser following happens: The code below comes in an endless loop though mySelector.select returns 0 every time. (The selector is registered for OP_READ). size = 1.
    while (true) {
    int n = mySelector.select();
    int size = mySelector.keys().size();
    if (n == 0) continue;
    Is this an expected result?
    How do I get to know what client has lost connection?
    My environment:
    W2000
    java 1.4.1 build 1.4.1_01-b01
    Browser used: IE 5.0
    Many thanks for your help on this matter!
    Regards Magnus Wistr�m

    What you're doing looks OK to me.
    I wonder whether your thread is being interrupted by Thread.intterupt() somewhere. Try putting a Thread.interrupted() before the select call.
    Sylvia.

  • Why have iTunes charged my account when I've got a £20 voucher on my account and the. Had to arrange a call back what was 2 days ago they called me back tonight then said the department was closed this is a wrong I want my money back!

    Why have iTunes charged my account when I've got a £20 voucher on my account and the. Had to arrange a call back what was 2 days ago they called me back tonight then the automated voice said the department was closed this is a wrong I want my money back! Or I'm gonna sell my iPad my kids iPods and iPhones mine and my wife's iPhones and the mac this is a **** take

    We are fellow users here on these forums, you are not talking to iTunes Support nor Apple.
    Were you buying content for yourself or gifting to another account ? If you were gifting content or an amount then that can only be done via credit card). If you weren't then you will need to contact iTunes Support : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • Why does the app (acrobat.exe) stay alive after the document is closed?

    Using system Explorer or HijackThis, it is apparent that the acrobat.exe app stays active after the document that called the app is closed.  Why?  and how do I stop it from happening?

    I have the same problem and it is irritating because if I print and save a pdf file using Acrobat, I cannot change the file name or delete the file  because the system somehow thinks the file is open in the Acrobat.exe application, even after I have closed out pdf file and all Adobe applications in my user account.   I need to go to the Task Manager and find the Acrobat application running under SYSTEM in order to stop the process so I can go back and change the file name or delete it...
    This did not occur until my recent update to Acrobat 9.4.2.220 .  Is this fixable somehow?

  • Need of closing the Socket to complete read at client

    Hi all,
    I have aproblem of reading a byte array from a socketconnection.
    My code is work but there is a small issue.
    Basically my problem is there is a need of closing the socket at the server to complete the reading of the byte array at client
    following is the server code which write the bytearray.
    ServerSocket  serversocket = new ServerSocket(Integer.parseInt(resources.getString("PORT")));
    Socket clientSocket = s.getServersocket().accept();
    DataOutputStream dt = new DataOutputStream(clientSocket.getOutputStream());
    dt.write(getImageasByteArray());     // getImageasByteArray returns a byte array
    //clientSocket.close();          // if not close clientSocket reading of the byte array not worksAs I mentioned above if the clientSocket is not closed the reading of the byte not completed at the client.
    client code which read the byte array
    SocketConnection sock = (SocketConnection) Connector.open("socket://" + hostname);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream inputStream = sock.openInputStream();
    int c = 0;
    while ((c = inputStream.read()) != -1)
         baos.write(c);
    System.out.println("read complete"); // this read complete never execute if not clientSocket is closed at serverI can't close the clientSocket because there are several threads at server some reads incoming commands and some write based on the commands.
    so please help me
    thank You

    Thank You again for answering
    my client is a j2me platform and it print this stackrace
    my code
    DataOutputStream dt = new DataOutputStream(clientSocket.getOutputStream());
    dt.write(ImageUtil.getImageasByteArray(img).length);
    dt.write(ImageUtil.getImageasByteArray(img));   //send byte array
    DataInputStream in = new DataInputStream(sock.openInputStream());    // openInputStream not getinputStream
    int length = in.readInt();
    System.out.println("read length=" + length);
    byte[] arr = new byte[length];  // read size
    in.readFully(arr); 
    java.lang.NegativeArraySizeException
            at net.chamika.mobility.client.CanvasKey.keyPressed(CanvasKey.java:90)
            at javax.microedition.lcdui.Canvas.callKeyPressed(Canvas.java:1121)
            at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(Display.java:2209)
            at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(Display.java:2952)
            at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(DefaultEventHandler.java:249)
            at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(AutomatedEventHandler.java:620)
            at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:699)
            at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)server ends arrays size as 5340
    client read it as -587212545
    Please help me.

  • System always auto-suspends when the lid is closed

    Hello,
    I am trying to prevent my laptop (a System76 Lemur Ultra 3) from suspending when the lid is closed.  No matter what I change in the configuration, the laptop always suspends when the lid is closed.  The output of journalctl is as follows after this happens:
    Feb 21 04:35:32 hostname systemd-logind[196]: Lid closed.
    Feb 21 04:35:32 hostname systemd-logind[196]: Suspending...
    Feb 21 04:35:32 hostname systemd[1]: Starting Sleep.
    Feb 21 04:35:32 hostname systemd[1]: Reached target Sleep.
    Feb 21 04:35:32 hostname systemd[1]: Starting Suspend...
    Feb 21 04:35:33 hostname systemd-sleep[2001]: Suspending system...
    Feb 21 04:35:33 hostname kernel: PM: Syncing filesystems ... done.
    Feb 21 04:35:33 hostname kernel: PM: Preparing system for mem sleep
    Feb 21 04:35:43 hostname kernel: Freezing user space processes ... (elapsed 0.06 seconds) done.
    Feb 21 04:35:43 hostname kernel: Freezing remaining freezable tasks ... (elapsed 0.01 seconds) done.
    Feb 21 04:35:43 hostname systemd[1]: Time has been changed
    Feb 21 04:35:43 hostname systemd[1]: systemd-tmpfiles-clean.timer: time change, recalculating next elapse.
    Feb 21 04:35:43 hostname systemd-logind[196]: Lid opened.
    Feb 21 04:35:43 hostname acpid[190]: client 1812[0:100] has disconnected
    Feb 21 04:35:43 hostname kernel: PM: Entering mem sleep
    Feb 21 04:35:43 hostname kernel: Suspending console(s) (use no_console_suspend to debug)
    Feb 21 04:35:43 hostname kernel: sd 0:0:0:0: [sda] Synchronizing SCSI cache
    Feb 21 04:35:43 hostname kernel: sd 0:0:0:0: [sda] Stopping disk
    Feb 21 04:35:43 hostname kernel: PM: suspend of devices complete after 1092.547 msecs
    Feb 21 04:35:43 hostname kernel: PM: late suspend of devices complete after 0.556 msecs
    Feb 21 04:35:43 hostname kernel: jme 0000:03:00.0: wake-up capability enabled by ACPI
    Feb 21 04:35:43 hostname kernel: ehci_hcd 0000:00:1d.0: wake-up capability enabled by ACPI
    Feb 21 04:35:43 hostname kernel: ehci_hcd 0000:00:1a.0: wake-up capability enabled by ACPI
    Feb 21 04:35:43 hostname kernel: PM: noirq suspend of devices complete after 66.095 msecs
    Feb 21 04:35:43 hostname kernel: ACPI: Preparing to enter system sleep state S3
    Feb 21 04:35:43 hostname kernel: PM: Saving platform NVS memory
    Feb 21 04:35:43 hostname kernel: Disabling non-boot CPUs ...
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 1 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 2 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 3 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 4 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 5 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 6 is now offline
    Feb 21 04:35:43 hostname kernel: smpboot: CPU 7 is now offline
    Feb 21 04:35:43 hostname kernel: Extended CMOS year: 2000
    Feb 21 04:35:43 hostname kernel: ACPI: Low-level resume complete
    Feb 21 04:35:43 hostname kernel: PM: Restoring platform NVS memory
    Feb 21 04:35:43 hostname kernel: Extended CMOS year: 2000
    Feb 21 04:35:43 hostname kernel: Enabling non-boot CPUs ...
    Feb 21 04:35:43 hostname systemd-sleep[2001]: System resumed.
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 1 APIC 0x2
    Feb 21 04:35:43 hostname kernel: CPU1 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 2 APIC 0x4
    Feb 21 04:35:43 hostname kernel: CPU2 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 3 APIC 0x6
    Feb 21 04:35:43 hostname kernel: CPU3 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 4 APIC 0x1
    Feb 21 04:35:43 hostname kernel: CPU4 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 5 APIC 0x3
    Feb 21 04:35:43 hostname kernel: CPU5 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 6 APIC 0x5
    Feb 21 04:35:43 hostname kernel: CPU6 is up
    Feb 21 04:35:43 hostname kernel: smpboot: Booting Node 0 Processor 7 APIC 0x7
    Feb 21 04:35:43 hostname kernel: CPU7 is up
    Feb 21 04:35:43 hostname kernel: ACPI: Waking up from system sleep state S3
    Feb 21 04:35:43 hostname kernel: ehci_hcd 0000:00:1a.0: wake-up capability disabled by ACPI
    Feb 21 04:35:43 hostname kernel: ehci_hcd 0000:00:1d.0: wake-up capability disabled by ACPI
    Feb 21 04:35:43 hostname kernel: PM: noirq resume of devices complete after 133.251 msecs
    Feb 21 04:35:43 hostname kernel: PM: early resume of devices complete after 0.425 msecs
    The first thing I did was to disable systemd's acpi features by setting /etc/systemd/logind.conf as follows:
    # This file is part of systemd.
    # systemd is free software; you can redistribute it and/or modify it
    # under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation; either version 2.1 of the License, or
    # (at your option) any later version.
    # See logind.conf(5) for details
    [Login]
    #NAutoVTs=6
    #ReserveVT=6
    #KillUserProcesses=no
    #KillOnlyUsers=
    #KillExcludeUsers=root
    #Controllers=
    #ResetControllers=cpu
    #InhibitDelayMaxSec=5
    HandlePowerKey=ignore
    HandleSuspendKey=ignore
    HandleHibernateKey=ignore
    HandleLidSwitch=ignore
    #PowerKeyIgnoreInhibited=no
    #SuspendKeyIgnoreInhibited=no
    #HibernateKeyIgnoreInhibited=no
    #LidSwitchIgnoreInhibited=yes
    IdleAction=suspend
    IdleActionSec=45min
    However, the behavior was the same as before.  I also tried setting
    LidSwitchIgnoreInhibited=no
    but after reading man 5 logind.conf it seems that this is unnecessary (and it had no effect when I tried it).
    acpid is also installed but I have commented out the contents of /etc/acpi/handler.sh as well as all the scripts in /etc/acpi/actions.  I noticed that there is also a UPower daemon which was installed as a dependency and thought that it might be triggering the suspend.  I tried setting
    IgnoreLid=true
    in /etc/UPower/UPower.conf but this also had no effect.
    systemctl list-units has the following output:
    UNIT LOAD ACTIVE SUB DESCRIPTION
    proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automount Point
    sys-devices-pci0000:00-0000:00:1b.0-sound-card0.device loaded active plugged /sys/devices/pci0000:00/0000:00:1b.0/sound/card0
    sys-devices-pci0000:00-0000:00:1c.2-0000:02:00.0-net-wlan0.device loaded active plugged /sys/devices/pci0000:00/0000:00:1c.2/0000:02:00.0/net/wlan0
    sys-devices-pci0000:00-0000:00:1c.3-0000:03:00.0-net-eth0.device loaded active plugged /sys/devices/pci0000:00/0000:00:1c.3/0000:03:00.0/net/eth0
    sys-devices-pci0000:00-0000:00:1d.0-usb2-2\x2d1-2\x2d1.2-2\x2d1.2.1-2\x2d1.2.1.1-2\x2d1.2.1.1.1-2\x2d1.2.1.1.1:1.2-sound-card1.device loaded active plugged 0819
    sys-devices-pci0000:00-0000:00:1d.0-usb2-2\x2d1-2\x2d1.2-2\x2d1.2.1-2\x2d1.2.1.3.device loaded active plugged Deskjet_5400_series
    sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loaded active plugged ST9500420AS
    sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loaded active plugged ST9500420AS
    sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded active plugged ST9500420AS
    sys-devices-pci0000:00-0000:00:1f.2-ata3-host2-target2:0:0-2:0:0:0-block-sr0.device loaded active plugged TSSTcorp_CDDVDW_SN-208AB
    sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS0
    sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS1
    sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS2
    sys-devices-platform-serial8250-tty-ttyS3.device loaded active plugged /sys/devices/platform/serial8250/tty/ttyS3
    sys-module-configfs.device loaded active plugged /sys/module/configfs
    sys-subsystem-net-devices-eth0.device loaded active plugged /sys/subsystem/net/devices/eth0
    sys-subsystem-net-devices-wlan0.device loaded active plugged /sys/subsystem/net/devices/wlan0
    -.mount loaded active mounted /
    dev-hugepages.mount loaded active mounted Huge Pages File System
    dev-mqueue.mount loaded active mounted POSIX Message Queue File System
    media-usbhd\x2dsda1.mount loaded active mounted /media/usbhd-sda1
    sys-kernel-config.mount loaded active mounted Configuration File System
    sys-kernel-debug.mount loaded active mounted Debug File System
    tmp.mount loaded active mounted Temporary Directory
    cups.path loaded active waiting CUPS Printer Service Spool
    systemd-ask-password-console.path loaded active waiting Dispatch Password Requests to Console Directory Watch
    systemd-ask-password-wall.path loaded active waiting Forward Password Requests to Wall Directory Watch
    acpid.service loaded active running ACPI event daemon
    atd.service loaded active running ATD daemon
    cronie.service loaded active running Periodic Command Scheduler
    cups.service loaded active running CUPS Printing Service
    dbus.service loaded active running D-Bus System Message Bus
    [email protected] loaded active running Getty on tty1
    laptop-mode.service loaded active exited Laptop Mode Tools
    polkit.service loaded active running Authorization Manager
    postfix.service loaded active running Postfix Mail Transport Agent
    systemd-journald.service loaded active running Journal Service
    systemd-logind.service loaded active running Login Service
    systemd-modules-load.service loaded active exited Load Kernel Modules
    systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
    systemd-sysctl.service loaded active exited Apply Kernel Variables
    systemd-tmpfiles-setup.service loaded active exited Recreate Volatile Files and Directories
    systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
    systemd-udevd.service loaded active running udev Kernel Device Manager
    systemd-user-sessions.service loaded active exited Permit User Sessions
    systemd-vconsole-setup.service loaded active exited Setup Virtual Console
    upower.service loaded active running Daemon for power management
    wicd.service loaded active running Wicd a wireless and wired network manager for Linux
    acpid.socket loaded active listening ACPID Listen Socket
    cups.socket loaded active running CUPS Printing Service Sockets
    dbus.socket loaded active running D-Bus System Message Bus Socket
    dmeventd.socket loaded active listening Device-mapper event daemon FIFOs
    lvmetad.socket loaded active listening LVM2 metadata daemon socket
    systemd-initctl.socket loaded active listening /dev/initctl Compatibility Named Pipe
    systemd-journald.socket loaded active running Journal Socket
    systemd-shutdownd.socket loaded active listening Delayed Shutdown Socket
    systemd-udevd-control.socket loaded active listening udev Control Socket
    systemd-udevd-kernel.socket loaded active running udev Kernel Socket
    basic.target loaded active active Basic System
    cryptsetup.target loaded active active Encrypted Volumes
    getty.target loaded active active Login Prompts
    graphical.target loaded active active Graphical Interface
    local-fs-pre.target loaded active active Local File Systems (Pre)
    local-fs.target loaded active active Local File Systems
    multi-user.target loaded active active Multi-User
    network.target loaded active active Network
    printer.target loaded active active Printer
    remote-fs.target loaded active active Remote File Systems
    sockets.target loaded active active Sockets
    sound.target loaded active active Sound Card
    suspend.target loaded active active Suspend
    swap.target loaded active active Swap
    sysinit.target loaded active active System Initialization
    systemd-tmpfiles-clean.timer loaded active waiting Daily Cleanup of Temporary Directories
    LOAD = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB = The low-level unit activation state, values depend on unit type.
    74 loaded units listed. Pass --all to see loaded but inactive units, too.
    To show all installed unit files use 'systemctl list-unit-files'.
    Any ideas on what might be causing the system to suspend when the lid is closed would be appreciated.
    Thanks
    Last edited by Superposition (2013-02-21 15:48:06)

    qinohe wrote:You don't have to disable acpi!
    Since you made the complete switch to systemd, why not let systemd handle this kind of events?
    I was referring to the suggestion of setting acpi=off on the kernel line.  systemd can only run a few preset actions on events like lid close (e.g. suspend, poweroff, ignore, etc.).  I need to run custom scripts.  Also, for some reason I still do not fully understand, it was not working properly.  The log in my original post seems to show that it was initiating the suspend.
    qinohe wrote:
    progandy wrote:Yes, it is easier, but my laptop should react differently depending on the power source. With AC power lid-switch locks the screen, in battery mode it suspends. That is impossible with systemd.
    Yes you need something like laptop-mode-tools for that, I know systemd will not do that, for now.
    But that is not the issue here!, the issue here is that the llid-switch-button' shouldn't be used at all.
    For as far as possible I would still recommend systemd to handle your events!, but it's your decision finally!
    You need acpid for that not laptop-mode-tools.  This is exactly what apcid is for --- running user scripts on ACPI events.
    Anyway, I finally have this fixed though I still have no idea what the problem was.  I ran out of ideas on how to fix it and #archlinux didn't know either so I went the painful but sure route.  I did full reinstall and reinstalled all programs.  logind was still behaving as this point (not ignoring it's logind.conf file as it seemed to be before the reinstall) after this so I concluded that the packages installed were not the problem at least with their default configs.  After that, I gradually restored the config files I cared about while testing to see if logind still worked correctly.  Contrary, to what I expected it never broke and I was able to restore all modified configs and get correct behavior.
    I suspect there was some old out of date config file somewhere that was causing the problem but it's hard to say which one it was.  I could probably figure it out with a bit more experimentation but have already spent enough time fixing this...
    In case anyone else needs a similar configuration, the relevant files are as follows.  This sets up the system to lock whenever systemd executes a suspend action.  It also sets up acpid to suspend on lid close.
    Make sure you have installed acpid and enabled it to run at startup.
    /etc/systemd/logind.conf
    # This file is part of systemd.
    # systemd is free software; you can redistribute it and/or modify it
    # under the terms of the GNU Lesser General Public License as published by
    # the Free Software Foundation; either version 2.1 of the License, or
    # (at your option) any later version.
    # See logind.conf(5) for details
    [Login]
    /etc/systemd/logind.conf
    #NAutoVTs=6
    #ReserveVT=6
    #KillUserProcesses=no
    #KillOnlyUsers=
    #KillExcludeUsers=root
    #Controllers=
    #ResetControllers=cpu
    #InhibitDelayMaxSec=5
    HandlePowerKey=ignore
    HandleSuspendKey=ignore
    HandleHibernateKey=ignore
    HandleLidSwitch=ignore
    #PowerKeyIgnoreInhibited=no
    #SuspendKeyIgnoreInhibited=no
    #HibernateKeyIgnoreInhibited=no
    #LidSwitchIgnoreInhibited=yes
    #IdleAction=ignore
    #IdleActionSec=30min
    /etc/acpi/handler.sh
    #!/bin/bash
    # Default acpi script that takes an entry for all actions
    case "$1" in
    button/power)
    case "$2" in
    PBTN|PWRF)
    logger 'PowerButton pressed'
    /usr/bin/systemctl poweroff
    logger "ACPI action undefined: $2"
    esac
    button/sleep)
    case "$2" in
    SLPB|SBTN)
    logger 'SleepButton pressed'
    /usr/bin/systemctl suspend
    logger "ACPI action undefined: $2"
    esac
    ac_adapter)
    case "$2" in
    AC|ACAD|ADP0)
    case "$4" in
    00000000)
    logger 'AC unpluged'
    /usr/sbin/laptop_mode auto
    00000001)
    logger 'AC pluged'
    /usr/sbin/laptop_mode auto
    esac
    logger "ACPI action undefined: $2"
    esac
    battery)
    case "$2" in
    BAT0)
    case "$4" in
    00000000)
    logger 'Battery online'
    /usr/sbin/laptop_mode auto
    00000001)
    logger 'Battery offline'
    /usr/sbin/laptop_mode auto
    esac
    CPU0)
    *) logger "ACPI action undefined: $2" ;;
    esac
    button/lid)
    case "$3" in
    close)
    logger 'LID closed'
    /usr/sbin/laptop_mode auto
    if [ $(cat /sys/class/power_supply/ADP0/online) -eq 0 ]; then
    /usr/bin/systemctl suspend
    fi
    open)
    logger 'LID opened'
    /usr/sbin/laptop_mode auto
    logger "ACPI action undefined: $3"
    esac
    logger "ACPI group/action undefined: $1 / $2"
    esac
    # vim:set ts=4 sw=4 ft=sh et:
    Last edited by Superposition (2013-02-23 23:15:54)

  • How to send to the socket EOF flag? Only socket.close() works fine :)

    I send a binary file from server socket to client socket. And I have some problem with client (but actually with server :) ).
    That is my server code which sends a file:
    OutputStream os = null;
    FileInputStream fis = null;
    try{
        fis = new FileInputStream( "some-file.png" );
    } catch ( FileNotFoundException e1 ) {}
    try {
        os = socket.getOutputStream();
        int c = -1;
        while( ( c = fis.read() ) != -1 ) {
            os.write( c );
        os.flush();
    //    os.close();
    } catch ( IOException e2 ) {}And that is client which receives a file:
    try {
        int sChunk = 8192;
        InputStream is = socket.getInputStream();
        FileOutputStream out = new FileOutputStream( "file.png" );
        byte[] buffer = new byte[ sChunk ];
        int length;
        while ( ( length = is.read( buffer, 0, sChunk ) ) > -1 )
            out.write( buffer, 0, length );
        out.close();
    } catch ( IOException e ) {
    }A client's while never continues cause I don't know how to send EOF from server.
    If I do: "os.close();" at the end of server sending - it works... But.. It closes my socket! But I want to work with socket after that :)
    How to send correct EOF flag from server? I think it's the root of all problems here..
    Edited by: JavaProger on Mar 22, 2009 4:43 PM

    os = socket.getOutputStream();
    int c = -1;
    while( ( c = fis.read() ) != -1 ) {
    os.write( c );
    }That's about as inefficient as it could be. Try this:
    int count;
    byte[] buffer = new byte[8192];
    while ((count = fis.read(buffer)) > 0)
    os.write(buffer, 0, count);
    os.close();
    Hmm, you're doing that in the client, why not in the server?
    } catch ( IOException e2 ) {}Never ignore an exception. In this case you should close the socket.
    } catch ( IOException e ) {See above.
    A client's while never continues cause I don't know how to send EOF from server.You can't send an EOF from the server. You can cause an EOS (end of stream on the socket) at the reader, by closing the socket, or shutting down its output, but then you can't send anything else on the socket. You have two choices:
    (a) use a connection per file. If the files are large the overhead is minimal.
    (b) use an application protocol to tell the reader when the file is complete. Typically this takes the form of sending the file length as a long first, and taking care to read exactly that many bytes when reading, which takes a bit of care, especially on the last buffer. Another way is to send the length ahead of each buffer, sending zero after the last buffer. You can do all this with the methods of DataInputStream and DataOutputStream.

  • How to get server data without reading from the socket stream?

    My socket client checks for server messages through
                while (isRunning) { //listen for server events
                    try {
                            Object o = readObject(socket); //wait for server message
                                tellListeners(socket, o);
                    } catch (Exception e) {
                        System.err.println("ERROR SocketClient: "+e);
                        e.printStackTrace();
                    try { sleep(1000); } catch (InterruptedException ie) { /* ignore */ }
                }//next client connectionwith readObject() being
        public Object readObject(Socket socket) throws ClassNotFoundException, IOException {
            Object result = null;
    System.out.println("readObject("+socket+") ...");
            if (socket != null && socket.isConnected()) {
    //            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                ObjectInputStream ois = new ObjectInputStream(new DataInputStream(socket.getInputStream()));
                try {
                    result = ois.readObject();
                } finally {
    //                socket.shutdownInput(); //closing of ois also closes socket!
        //            try { ois.close(); } catch (IOException ioe) { /* ignore */ }
            return result;
        }//readObject()Why does ois.readObject() block? I get problems with this as the main while loop (above) calls readObject() as it's the only way to get server messages. But if i want to implement a synchronous call in adition to this asynchronous architecture (call listeners), the readObject() call of the synchronous method comes to late as readObject() call of the main loop got called before and therefore also gets the result of the (later) synchronous call.
    I tried fideling around with some state variables, but that's ugly and probably not thread safe. I'm looking for another solution to check messages from the server without reading data from the stream. is this possible?

    A quick fix:
    - Add a response code at the beginning of each message returned from the server indicating if the message is a synchronous response or a callback (asynch);
    - Read all messages returned from the server in one thread and copy callback messages in a calback message queue and the synch responses in an synch responses queue;
    - Modify your synchronous invocation to retrieve the response from the responses queue instead from the socket. Read the callback messages from the corresponding queue instead from the socket.
    Also take a look at my website. I'm implementing an upgraded version of this idea.
    Catalin Merfu
    High Performance Java Networking
    http://www.accendia.com

  • I am using a Photoshop cs2, and I wonder if it is possible to keep the settings of the guidelines when closing an image, with the actual document ? It would be nice to have the guidelines locked down, I find it than when opening the same or another image,

    I am using a Photoshop cs2, and I wonder if it is possible to keep the settings of the guidelines when closing an image, with the actual document ? It would be nice to have the guidelines locked down, I find it than when opening the same or another image, the guidelines are not locked, it is annoying to have to lock them down again. and it would actually be nice, to ba able to give specific directions when placing the guidelines. Thanks

    Then why are the guides unlocked when I reopen a document that I saved with the guides locked ?
    Thanks.

  • My IPad cannot download live Tv from skygo. I have no problem with my lap top so I assume the broad band is okay. Can anybody suggest why the live streaming will not work on my iPad one.

    My IPad cannot download live Tv from skygo. I have no problem with my lap top so I assume the broad band is okay. Can anybody suggest why the live streaming will not work on my iPad .

    Are you using the Sky Go app to try and watch it ? If so are you logged in with your Sky account ?
    If you are using the app then you could try closing the app completely and see if it works when you re-open it : from the home screen (i.e. not with Sky Go 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Sky Go app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work then you could try a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

Maybe you are looking for