Sending the key with Socket

Hello!
I have made an application that encrypts a byte[], sends it to a server.
And after that i am trying to decrypt it. But that gives me problem.
The exception i get is:
BadPaddingException: javax.crypto.BadPaddingException: Given final block not properly padded.
This is my code.
The client
import java.net.*;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
import java.util.*;
class Client
  public static void main(String a[])
    Socket socket = null;
    try
      // Create Key
      KeyGenerator kg = KeyGenerator.getInstance("DES");
      SecretKey secretKey = kg.generateKey();
      // Create Cipher
      Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
      desCipher.init(Cipher.ENCRYPT_MODE, secretKey);
      socket = new Socket("localhost", 3000);
      DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
      ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
      File file = new File("Mattias.jpg");
      FileInputStream fileInputStream = new FileInputStream(file);
      byte[] bytes = new byte[(int)file.length()];
      fileInputStream.read(bytes);
      fileInputStream.close();
      byte[] encryptedBytes = new byte[(int)file.length()];
      encryptedBytes = desCipher.doFinal(bytes);
      out.writeInt((int)file.length());
      out.writeObject((Object)secretKey);
      dataOutputStream.write(encryptedBytes);
      out.flush();
      dataOutputStream.flush();
      out.close();
      dataOutputStream.close();
    catch(IOException e)
      e.printStackTrace();
    catch (NoSuchPaddingException e)
      System.err.println("Padding problem: " + e);
    catch (NoSuchAlgorithmException e)
      System.err.println("Invalid algorithm: " + e);
    catch (InvalidKeyException e)
      System.err.println("Invalid key: " + e);
    catch (IllegalBlockSizeException e)
      System.err.println("IllegalBlockSizeException: " + e);
    catch (BadPaddingException e)
      System.err.println("BadPaddingException: " + e);
    finally
      try
        socket.close();
      catch(IOException e)
        e.printStackTrace();   
The server
import java.net.*;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.*;
import java.util.*;
class Server
  public static void main(String a[]) throws IOException
    new Server().listen(3000);
  public void listen(int port) throws IOException
    ServerSocket serverSocket = new ServerSocket(port);
    new SocketHandler(serverSocket.accept()).start();
  class SocketHandler extends Thread
    Socket socket = null;
    SocketHandler(Socket socket)
      this.socket = socket;
    public void run()
      try
        SecretKey secretKey = null;
        File file = new File("file.jpg");
        OutputStream fileOutputStream = new FileOutputStream(file);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(socket.getInputStream());
        ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
        int fileSize = in.readInt();
        byte[] encryptedBytes = new byte[fileSize * 8];
        byte[] bytes = new byte[fileSize];
        secretKey = (SecretKey)in.readObject();
        // Create Cipher
        Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
        desCipher.init(Cipher.DECRYPT_MODE, secretKey);
        int i = -1;
        while (true)
          i = bufferedInputStream.read(encryptedBytes, 0, encryptedBytes.length);
          bytes = desCipher.doFinal(encryptedBytes);
          if (i == -1)
            break;
          fileOutputStream.write(bytes, 0, i);
        bufferedInputStream.close();
        fileOutputStream.flush();
        fileOutputStream.close();
      catch (IOException ioe)
        ioe.printStackTrace();
        catch(ClassNotFoundException cnfe)
        cnfe.printStackTrace();
      catch (NoSuchPaddingException e)
        System.err.println("Padding problem: " + e);
      catch (NoSuchAlgorithmException e)
        System.err.println("Invalid algorithm: " + e);
      catch (InvalidKeyException e)
        System.err.println("Invalid key: " + e);
      catch (IllegalBlockSizeException e)
        System.err.println("IllegalBlockSizeException: " + e);
      catch (BadPaddingException e)
        System.err.println("BadPaddingException: " + e);
      finally
        try
          socket.close();
        catch (IOException ioe)
          ioe.printStackTrace();
}What am i doing wrong? How should i solve it?

This looks suspect -DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
      ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());It is normally a bad idea to attach a single OutputStream to 2 or more 'filter' streams.
You could always sent the data as an object i.e.out.writeObject(encryptedBytes);Also, you make the assumption that the encrypted length is the same as the file length. With PKCS5Padding this is never the case since it pads with 1 to 8 bytes to make up to the block size. This is probably the cause of the BadPaddingException. If you send the encrpted data over as an object then you don't need to send the length.
Your stream uses in the client and server differ. You have no DataInputStream in the server to match the DataOuputStream in the client. To be safe, stick to Object streams or Data streams but don't mix.
P.S. Isn't sending the key with the cipher text a litte insecure!!!

Similar Messages

  • Issue in sending the email with XL attachment in ECC version

    Hi,
    I have an issue with sending the email with XL attachment. My program is sending a mail to the receiver with XLS as attachment. Recently we have migrated from 4.6B to ECC version. Same code was worked in 4.6B.But it is not working in ECC version.When i try to open the attachment, i get a Dialog Box with the following message
    "The file is not in a recognizable format.
    1. if you know the file is from another program whih is incompatible with Microsoft excel,click cancel,then open this file in its original application
    2.If you suspect the file is damaged, click help for more information about solving theproblem.
    3.if you still want to see what text is contained in the file, click OK.Then click the text import wizard. "
    when i click OK, the excel sheet is opening with all required data.
    Can anyone kindly tell me why this is happening.
    I am also attaching part of the coding related to this requirement.
    *&      Form  BUILD_XLS_DATA_TABLE
          text
    -->  p1        text
    <--  p2        text
    FORM build_xls_data_table.
      DATA: w_total(13),
      w_clabs(13),
      w_cinsm(13),
      w_ceinm(13),
      w_cretm(13),
      w_cspem(13),
      w_cumlm(13),
      w_exp_date(8),
      w_v_totalp(13),
      w_min_rem(8),
      w_ersda(10),
      w_hsdat(10),
      w_vfdat(10),
      w_ship_date(10),
      w_plnmg(13),
       w_mhdrz(4).
      CLEAR: w_total, w_clabs, w_cinsm, w_ceinm, w_cspem, w_exp_date,
      w_v_totalp, w_min_rem, w_ersda, w_hsdat, w_vfdat, w_ship_date,
      w_plnmg, w_mhdrz.
      w_total = it_batch1-total.
      w_clabs = it_batch1-clabs.
      w_cinsm = it_batch1-cinsm.
      w_ceinm = it_batch1-ceinm.
      w_cspem = it_batch1-cspem.
      w_cumlm = it_batch1-cumlm.
      w_cretm = it_batch1-cretm.
      w_exp_date = it_batch1-exp_date.
      w_v_totalp = it_batch1-v_totalp.
      w_min_rem = it_batch1-min_rem.
      w_plnmg = it_batch1-plnmg.
      w_mhdrz = it_batch1-mhdrz.
      CONCATENATE it_batch1-ersda6(2) it_batch1-ersda4(2)
                  it_batch1-ersda+0(4) INTO w_ersda SEPARATED BY '.'.
      CONCATENATE it_batch1-hsdat6(2) it_batch1-hsdat4(2)
                  it_batch1-hsdat+0(4) INTO w_hsdat SEPARATED BY '.'.
      CONCATENATE it_batch1-vfdat6(2) it_batch1-vfdat4(2)
                  it_batch1-vfdat+0(4) INTO w_vfdat SEPARATED BY '.'.
      CONCATENATE it_batch1-ship_date6(2) it_batch1-ship_date4(2)
                  it_batch1-ship_date+0(4) INTO w_ship_date SEPARATED BY '.'
      CONCATENATE
      it_batch1-werks it_batch1-mtart it_batch1-matnr it_batch1-maktg
    it_batch1-prdha it_batch1-prctr it_batch1-ktext  it_batch1-dispo
      it_batch1-charg it_batch1-lgort it_batch1-herkl w_clabs
      w_cinsm w_ceinm w_cretm w_cspem
      w_cumlm w_total  it_batch1-meins  it_batch1-v_spr_unit
      w_v_totalp it_batch1-waers w_plnmg  it_batch1-meins
      w_ersda w_hsdat w_vfdat  w_exp_date
       w_ship_date  w_mhdrz  w_min_rem it_batch1-zlifer
       it_batch1-doknr it_batch1-dokar it_batch1-doktl  it_batch1-dokvr
               INTO L_STRING SEPARATED BY CON_TAB.
                  INTO l_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
      WHILE l_string <> space.
        CALL FUNCTION 'TEXT_SPLIT'
          EXPORTING
            length       = 255
            text         = l_string
            as_character = 'X'
          IMPORTING
            line         = it_attach
            rest         = l_string.
        IF l_string = space.
       CONCATENATE IT_ATTACH CON_CRET INTO IT_ATTACH.
          CONCATENATE it_attach cl_abap_char_utilities=>cr_lf INTO it_attach.
          APPEND it_attach.
          CLEAR it_attach.
        ELSE.
          APPEND it_attach.
          CLEAR it_attach.
        ENDIF.
      ENDWHILE.
    move l_string to it_attach .
    CONCATENATE it_attach cl_abap_char_utilities=>cr_lf INTO it_attach.
    APPEND it_attach.
    CLEAR it_attach.
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          text
    -->  p1        text
    <--  p2        text
    FORM send_file_as_email_attachment.
      DATA:w_length TYPE i.
      DATA:  w_cnt TYPE i,
              w_sent_all(1) TYPE c,
              w_doc_data LIKE sodocchgi1,
              gd_error    TYPE sy-subrc,
              gd_reciever TYPE sy-subrc,
              t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name  = 'SAPRPT'.
    w_doc_data-obj_descr = text-034 .
    w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
    DESCRIBE TABLE it_attach LINES w_cnt.
      DESCRIBE TABLE it_message LINES w_cnt.
      READ TABLE it_message INDEX w_cnt.
    w_length = STRLEN( it_attach ).
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_message ).
      w_doc_data-obj_langu  = sy-langu.
    w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = text-034.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
    ***Start of changes by 501507008 on 29.01.2009
      t_packing_list-obj_descr  = 'MAIL BODY'.
    ***End of changes by 501507008 on 29.01.2009
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  'XLS'.
      t_packing_list-obj_descr  =  text-034.
      t_packing_list-obj_name   =  'filename'.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      LOOP AT it_adr6.
        t_receivers-receiver = it_adr6-smtp_addr.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        APPEND t_receivers.
      ENDLOOP.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
         document_data              = w_doc_data
         put_in_outbox              = 'X'
         sender_address             = ' '
         sender_address_type        = ' '
         commit_work                = 'X'
       IMPORTING
         sent_to_all                = w_sent_all
       TABLES
         packing_list               = t_packing_list
         contents_bin               = t_attachment
         contents_txt               = it_message
         receivers                  = t_receivers
       EXCEPTIONS
         too_many_receivers         = 1
         document_not_sent          = 2
         document_type_not_exist    = 3
         operation_no_authorization = 4
         parameter_error            = 5
         x_error                    = 6
         enqueue_error              = 7
         OTHERS                     = 8.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data                    = w_doc_data
         put_in_outbox                    = 'X'
      commit_work                      = ' '
    IMPORTING
      sent_to_all                      =
      new_object_id                    =
    tables
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
      contents_hex                     =
      object_para                      =
      object_parb                      =
       exceptions
         too_many_receivers               = 1
         document_not_sent                = 2
         document_type_not_exist          = 3
         operation_no_authorization       = 4
       parameter_error                  = 5
       x_error                          = 6
       enqueue_error                    = 7
       OTHERS                           = 8.
      IF sy-subrc <> 0.
      ENDIF.
    ENDFORM.                    " SEND_FILE_AS_EMAIL_ATTACHMENT

    Hi,
    could you tell me which opeion should i select in SCOT under INT node. I have tried with diffrent options. but no luck.
    SAPscript/Smart Forms  - No Conversion
    ABAP List                     - No Conversion
    Business Object/Link     - No Conversion
    RAW Text                     - No Conversion

  • Filling up a pdf form which I received as email. I opened it on my adobe reader 11 and filled up the highlighted fields. Yet when I click on the send via mail it says changes will not be included. How do I send the form with changes?

    Filling up a pdf form which I received as email. I opened it on my adobe reader 11 and filled up the highlighted fields. Yet when I click on the send via mail it says changes will not be included. How do I send the form with changes?
    The add annotations field shows as not allowed in the security options. So how do I send this form back with the changes??

    I think you you need to click 'save' first, then it is saved to acrobat, where it will prompt to send.

  • HT1338 Why when trying to change my apple ID password apple won't send the email with the change instructions?

    Why when trying to change my apple ID password apple won't send the email with the change instructions?

    There is a contact link.
    Apple ID Support

  • Bex Hierarchy showing just the key with Attributes ????

    Hierarchy showing just the key with Attributes ????  I want the Text without attribute!
    I had created a Hierarchy manually on 0companycode characteristic, but I have some problems.
    1 u2013 Itu2019s showing just the KEY (On query Design is marked to show the text , and Iu2019m on the proper language).
    2 u2013 On the last lever that is the company code, is showing the key with all attributes like this.
    ->     CONTRY_BR
                    -> KW11 Contry Canada Chart of account 0001 Currency 01
    I want just the Text without the attributes.
    Regards
    Edited by: Marcus Coufal on Mar 4, 2011 1:53 PM

    On the caracteristic -> attribute put 0 on  "Order For"

  • Send Mutliple Messages with Socket?

    I was wondering how to send multiple messages across a socket and server using TCP with Flash. I got the writeUTFBytes and readUTFBytes working, but the messages only send one at a time.
    Here's an example from the client sending messages to the server:
    if (keys[p1_jump_key])
                    p1_up = "down";
                    sock.writeUTFBytes("p1_up_down");
                    sock.flush();
                else
                    p1_up = "up";
                    sock.writeUTFBytes("p1_up_up");
                    sock.flush();
                if (keys[p1_crouch_key])
                    p1_down = "down";
                    sock.writeUTFBytes("p1_down_down");
                    sock.flush();
                else
                    p1_down = "up";
                    sock.writeUTFBytes("p1_down_up");
                    sock.flush();
    And here's what the server does to send the message back to the client:
    var socket:Socket = event.target as Socket;
        var message:String = socket.readUTFBytes(socket.bytesAvailable);
        for each (var socket:Socket in clientSockets)
            socket.writeUTFBytes(message);
            socket.flush();
    And finally here's an example from the client reading the message from the server:
    switch (msg)
                    case "p1_down_down" :
                        p1_down = "down";
                        break;
                    case "p1_down_up" :
                        p1_down = "up";
                        break;
                    case "p1_up_down" :
                        p1_up = "down";
                        break;
                    case "p1_up_up" :
                        p1_up = "up";
                        break;
    As you can probably tell, when the messages are sending all at once, they sort of kick each other out and nothing really happens. I was wondering how I'd be able to send multiple messages at once? Thank you.

    You are not missing something here and no one here can help you. This is not an included Bluetooth profile with the iPhone at the present time anyway.
    If you purchased your iPhone within the last 14 days, you can return it for credit less a 10% restocking fee and if not, here is Apple's feedback link for the iPhone.
    http://www.apple.com/feedback/iphone.html

  • I suppose it is the problem with socket connection,Please help

    Hi,
    I'm trying to build a chat server in Java on Linux OS.I've created basically 2 classes in the client program.The first one shows the login window.When we enter the Login ID & password & click on the ok button,the data is sent to the server for verification.If the login is true,the second class is invoked,which displays the messenger window.This class again access the server
    for collecting the IDs of the online persons.But this statement which reads from the server causes an exception in the program.If we invoke the second class independently(ie not from 1st class) then there is no problem & the required data is read from the server.Can anyone please help me in getting this program right.I'm working on a p4 machine with JDK1.4.
    The Exceptions caused are given below
    java.net.SocketException: Connection reset by peer: Connection reset by peer
    at java.net.SocketInputStream.SocketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:119)
         at java.io.InputStreamReader$CharsetFiller.readBytes(InputStreanReader.java :339)
         at java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:374)
         at java.io.InputStreamReader.read(InputStreamReader.java:511)
         at java.io.BufferedReader.fill(BufferedReader.java:139)
         at java.io.BufferedReader.readLine(BufferedReader.java:299)
         at java.io.BufferedReader.readLine(BufferedReader.java:362)
         at Login.LoginData(Login.java:330)
         at Login.test(Login.java:155)
         at Login$Buttonhandler.actionPerformed(Login.java:138)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1722)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:17775)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:4141)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:253)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:261)
         at java.awt.Component.processMouseEvent(Component.java:4906)
         at java.awt.Component.processEvent(component.java:4732)
         at java.awt.Container.processEvent(Container.java:1337)
         at java.awt.component.dispatchEventImpl(Component.java:3476)
         at java.awt.Container.dispatchEventImpl(Container.java:1399)
         at java.awt.Component.dispatchEvent(Component.java:3343)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3302)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3014)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2967)
         at java.awt.Container.dispatchEventImpl(Container.java:1373)
         at java.awt.window.dispatchEventImpl(Window.java:1459)
         at java.awt.Component.dispatchEvent(Component.java:3343)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:439)
         at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:131)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
         My program looks somewhat like this :
    1st class definition:
    public class Login extends Jframe// Login is the name of the first class;
    Socket connection;
    DataOutputStream outStream;
    BufferedReader inStream;
    Frame is set up here
    public class Buttonhandler implements ActionListener
    public void actionPerformed(ActionEvent e) {
    String comm = e.getActionCommand();
    if(comm.equals("ok")) {
    check=LoginCheck(ID,paswd);
    test();
    public void test() //checks whether the login is true
    if(check)
    new Messenger(ID);// the second class is invoked
    public boolean LoginCheck(String user,String passwd)
    //Enter the Server's IP & port below
    String destination="localhost";
    int port=1234;
    try
    connection=new Socket(destination,port);
    }catch (UnknownHostException ex){
    error("Unknown host");
    catch (IOException ex){
    ex.printStackTrace ();
    error("IO error creating socket ");
    try{
    inStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    outStream=new DataOutputStream(connection.getOutputStream());
    }catch (IOException ex){
    error("IO error getting streams");
    ex.printStackTrace();
    System.out.println("connected to "+destination+" at port "+port+".");
    BufferedReader keyboardInput=new BufferedReader(new InputStreamReader(System.in));
    String receive=new String();
    try{
    receive=inStream.readLine();
    }catch(IOException ex){ error("Error reading from server");}
    if(receive.equals("Logintrue"))
    check=true;
    else
    check=false;
    try{
    inStream.close();
    outStream.close();
    connection.close();
    }catch (IOException ex){
    error("IO error closing socket");
    return(check);
    // second class is defined below
    public class Messenger
    Socket connect;
    DataOutputStream outStr;
    BufferedReader inStr;
    public static void main(String args[])
    { Messenger mes = new Messenger(args[0]);}
    Messenger(String strg)
    CreateWindow();
    setupEvents();
    LoginData(strg);
    fram.show();
    void setupEvents()
    fram.addWindowListener(new WindowHandler());
    login.addActionListener(new MenuItemHandler());
    quit.addActionListener(new MenuItemHandler());
    button.addActionListener(new Buttonhandle());
    public void LoginData(String name)
    //Enter the Server's IP & port below
    String dest="localhost";
    int port=1234;
    int r=0;
    String str[]=new String[40];
    try
    connect=new Socket(dest,port);
    }catch (UnknownHostException ex){
    error("Unknown host");
    catch (IOException ex){
    ex.printStackTrace ();
    error("IO error creating socket ");
    try{
    inStr = new BufferedReader(new InputStreamReader(connect.getInputStream()));
    outStr=new DataOutputStream(connect.getOutputStream());
    }catch (IOException ex){
    error("IO error getting streams");
    ex.printStackTrace();
    String codeln=new String("\n");
    try{
    outStr.flush();
    outStr.writeBytes("!@*&!@#$%^");//code for sending logged in users
    outStr.writeBytes(codeln);
    outStr.write(13);
    outStr.flush();
    String check="qkpltx";
    String receive=new String();
    try{
    while((receive=inStr.readLine())!=null) //the statement that causes the exception
    if(receive.equals(check))
    break;
    else
         str[r]=receive;
         r++;
    }catch(IOException ex){ex.printStackTrace();error("Error reading from socket");}
    catch(NullPointerException ex){ex.printStackTrace();}
    } catch (IOException ex){ex.printStackTrace();
    error("Error reading from keyboard or socket ");
    try{
    inStr.close();
    outStr.close();
    connect.close();
    }catch (IOException ex){
    error("IO error closing socket");
    for(int l=0,k=1;l<r;l=l+2,k++)
    if(!(str[l].equals(name)))
    stud[k]=" "+str[l];
    else
    k--;
    public class Buttonhandle implements ActionListener
    public void actionPerformed(ActionEvent e) {
    //chat with the selected user;
    public class MenuItemHandler implements ActionListener
    public void actionPerformed(ActionEvent e)
    String cmd=e.getActionCommand();
    if(cmd.equals("Disconnect"))
    //Disconnect from the server
    else if(cmd.equals("Change User"))
         //Disconnect from the server & call the login window
    else if(cmd.equals("View Connection Details"))
    //show connection details;
    public class WindowHandler extends WindowAdapter
    public void windowClosing(WindowEvent e){
    //Disconnect from server & then exit;
    System.exit(0);}
    I�ll be very thankful if anyone corrects the mistake for me.Please help.

    You're connecting to the server twice. After you've successfully logged in, pass the Socket to the Messenger class.
    public class Messenger {
        Socket connect;
        public static void main(String args[]) {
            Messenger mes = new Messenger(args[0]);
        Messenger(Socket s, String strg) {
            this.connect = s;
            CreateWindow();
            setupEvents();
            LoginData(strg);
            fram.show();
    }

  • ICloud IMAP server does not send the CAPABILITY with CRLF

    IMAP iCloud server does not send the CAPABILITY response with CRLF appended as per RFC 3501. Please find the log snippet
    11-05 10:50:52.462 29603 29988 D Email   : open :: socket openjava.io.BufferedInputStream@43a726a8 | java.io.BufferedOutputStream@43a72b68
    11-05 10:50:52.502 29603 29988 D Email   : <<< #null# ["OK", ["CAPABILITY", "st11p00mm-iscream023", "1S", "XAPPLEPUSHSERVICE", "IMAP4", "IMAP4rev1", "SASL-IR", "AUTH=ATOKEN", "AUTH=PLAIN"], "iSCREAM ready to rumble (1S:1092) st11p00mm-iscream023 [42:4469:15:50:53:39]"]
    11-05 10:50:52.502 29603 29988 D Email   : >>> 1 CAPABILITY
    11-05 10:50:52.552 29603 29988 D Email   : <<< #null# ["CAPABILITY", "st11p00mm-iscream023", "1S", "XAPPLEPUSHSERVICE", "IMAP4", "IMAP4rev1", "SASL-IR", "AUTH=ATOKEN", "AUTH=PLAIN"]
    11-05 10:50:52.562 29603 29988 D Email   : <<< #1# ["OK", "!!"]
    11-05 10:50:52.582 29603 29988 D Email   : >>> [IMAP command redacted]
    11-05 10:50:52.682 29603 29988 D Email   : <<< #2# ["OK", ["CAPABILITY", "XAPPLEPUSHSERVICE", "IMAP4", "IMAP4rev1", "ACL", "QUOTA", "LITERAL+", "NAMESPACE", "UIDPLUS", "CHILDREN", "BINARY", "UNSELECT", "SORT", "CATENATE", "URLAUTH", "LANGUAGE", "ESEARCH", "ESORT", "THREAD=ORDEREDSUBJECT", "THREAD=REFERENCES", "CONDSTORE", "ENABLE", "CONTEXT=SEARCH", "CONTEXT=SORT", "WITHIN", "SASL-IR", "SEARCHRES", "XSENDER", "X-NETSCAPE", "XSERVERINFO", "X-SUN-SORT", "ANNOTATE-EXPERIMENT-1", "X-UNAUTHENTICATE", "X-SUN-IMAP", "X-ANNOTATEMORE", "XUM1", "ID", "IDLE"], "User test logged in"]
    11-05 10:50:52.682 29603 29988 D Email   : >>> 3 CAPABILITY
    11-05 10:50:52.742 29603 29988 W Email   : Exception detected: Expected 000a (
    )1-05 10:50:52.742 29603 29988 W Email   : ) but got 000d (
    This is happening only when CAPABILITY command is sent follwed by LOGIN command. Please check this issue.

    If you want your mail delivered properly the Official Host Name of the sending server should match the PTR (reverse DNS) of the sending IP Address, and there should be an "A" record that matches the OHN as well.
    Example:
    mail.yourdomain.com (Official Host Name) on 123.123.123.123
    PTR for 123.123.123.123 should match mail.yourdomain.com
    There should be an A record in yourdomain.com pointing to 123.123.123.123
    Kostas

  • How to solve the exception with socket and PrintWriter constructor

    I am working on a socket communication program and everything works fine on my computer until my boss moved my code to his computer. The following is the client code.
    The client program terminate with exception "Couldn't get I/O for the connection to local host." I have no idea how to solve the problem because there is no way out if the two statements (socket constructor and PrintWriter) fail.
    /*the program shall close connections and exit if the user clicks 'e'.*/
    public class LocalClient extends JPanel implements KeyListener {
    Socket localSocket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    char fromServer = ' ';
    public LocalClient() {
    try {
    localSocket = new Socket("a029243.cs.uregina.ca", 4444);
    out = new PrintWriter(localSocket.getOutputStream(), true);
    } catch (UnknownHostException e) {
    System.err.println("Don't know about local host.");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for the connection to
    local host.");
    System.exit(1);
    addKeyListener(this);
    }//end of constructor
    /*the component needs to be focused in order to respond to user input */
    public boolean isFocusTraversable() {return true;}
    public void keyPressed(KeyEvent evt) {
    public void keyReleased (KeyEvent evt) {
    public void keyTyped(KeyEvent evt) {
    System.out.println("key typed is called ");
    char fromClient=evt.getKeyChar();
    if (fromClient!= ' ') {
    if (fromClient=='e')
    try {
    out.close();
    localSocket.close();
    System.exit(1);
    } catch (IOException e)
    {System.out.println("connection closed");}
    else {
    System.out.println("Client: " +
    fromClient);
    out.println(fromClient);
    out.flush();}
    public static void main(String[] args) throws IOException {
    JFrame frame1=new JFrame();
    Container contentPane=frame1.getContentPane();
    LocalClient lc = new LocalClient();
    contentPane.add(lc);
    frame1.pack();
    frame1.setSize(50,50);
    frame1.setVisible(true);
    }//end of main
    } //end of class

    Add e.printStackTrace() or System.out.println(e) to the catch block of the IOException. The IOException has a message about what went wrong.

  • Problems with sending the Job_ID with activity EMAIL from a processflow

    Hello everybody,
    i have a problem with a simple process flow.
    I want to send an EMail that contains in the MESSAGE_BODY the Job_ID from the started workflow. For that reason i wrote a function with a select statement that gives back the number.
    Code:
    l_owb_id VARCHAR2(20);
    BEGIN
    select to_char(top_level_execution_audit_id)
    into l_owb_id
    from ALL_RT_AUDIT_EXECUTIONS
    where task_name = 'XYZ'
    and created_on like sysdate;
    return (l_owb_id);
    END;
    The function works fine. So i placed it into my workflow. Now i wanted to bind the MESSAGE_BODY from the activity EMAIL with the parameter of the function. But when i click validate it shows following error:
    VLD-10042: Parameter MESSAGE_BODY of EMAIL is incorrectly bound. Output of cannot be converted into a constant value.
    VLD-10042: Activity MESSAGE_BODY of EMAIL is currently bound to parameter GET_OWB_ID of .Activities must be bound through an intermediate variable
    Can anyone help me how to fix that proplem. How can i send the Process ID per activity EMAIL in a Workflow. On the internet i didn't found anything helpful, so any help would be appreiciated.
    Kind regards,
    Daniel

    You need to create Variable and then bind the value from your function to that variable and than use that variable as parameter for email MESSAGE_BODY.
    So you will have:
    Variable: p_id
    Return parameter of your function will be bind to p_id and message_body of your email will be bind to p_id.

  • I am using iPhoto version 9.6 and I can no longer get an email sent with a photo attached. I get an error message saying the email did not go through because the server did not reply. I can send the photo with Mail. Help!

    I have upgraded to Yosemite and also updated the iPhoto application to version 9.6. I am no longer able to send a photo from iPhoto via email. I get an error message saying the server is not responding. But, when using the same server in Mail, I can attach the photo and send it. My wife is using the older version of iPhoto and it works fine.
    I have checked the settings for the outgoing server, etc. and the Mail settings match those in iPhoto.
    Could this be due to either the Yosemite upgrade or the iPhoto upgrade?

    This solution is for those of you using 2-step verification for your Apple ID and are using iCloud as the mail server that you are trying to mail photos with.
    I too had this issue. The problem in my case occurred because I had setup 2-step authentication for my Apple ID. If you have done this then you will get the error message "the mail server did not recognize your email/password...". To solve the problem go to:
    https://appleid.apple.com
    Click "Manage Your Apple ID"
    Verify your identity with the device you selected (if this step does not show up then you have not likely set up 2-step authentication and this is not your solution)
    Click Password and Security in the left column
    Click Generate an app-specific password
    Enter iPhoto as the name of the app
    Copy the password and paste this into the password box in iPhoto where you would normally enter your apple ID (in the mail account section in iPhoto preferences).
    And...voila' (I hope)

  • How to send the mail with multiple file attachments ?

    Sending mails with multiple files as attachments.

    You need to start from the app, assuming that it has an email function, that contains the files that you want to send as attachments. The Photos app allows you to send up to 5 photos on the same email, but if you want to send multiple file types then you need an app that supports all those file types. I use the GoodReader app which supports quite a few document/file types (e.g. PDF, Excel, Word, pictures), and from that I can select multiple files (including different types) and attach them to the same email.

  • Disabling the keys with my Java Program

    I have a program that extends a JWindow. I would like to make this program my destop, as in disabling all function keys on the keyboard including ctrl+alt+del and others like that.
    Some Internet cafe shops use this technique to restrict unauthorised customers from accessing their PCs.
    If anyone knows how, please help.
    Thanks in advance.

    Keys that are listened to by the Window Environment cannot be intercepted with Java alone. This include Ctrl-Alt-Del, as well as Alt-Tab for MS Windows. You would need JNI to do this.
    If you use Linux, you could do it in pure Java, with one exception. Ctrl-Alt-Del would terminate X, and bring you to a console login. You may be able to disable that somewhere in the X configuration. This would prevent anyone from getting access to the system, unless they have the login for it. To do this you would need to setup X so it starts without the Gnome/KDE Desktop Manager, and runs your full screen Java app instead.

  • MultiCast sending the String with delay 5s.

    Dear all
    I had written a program that multicast-sends a string every five seconds to the multicast group 234.5.6.7 on port 8111. The string to be sent is obtained by the following statement: String str = (new Information()).toString() and is as following:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.Timer;
    import java.awt.event.ActionListener;
    public class Multicast implements ActionListener {
       public static void main(String args[]) {
        try {
          String str = new Information().toString();
          InetAddress group = InetAddress.getByName("234.5.6.7");
          MulticastSocket s = new MulticastSocket(8111);
          s.joinGroup(group);
          DatagramPacket hi = new DatagramPacket(str.getBytes(), str.length(), group, 8111);
          int delay = 5000; //milliseconds
          ActionListener taskPerformer = new ActionListener();
          new Timer(delay, taskPerformer).start();
          s.leaveGroup(group);
         } catch (Exception e) {
          System.out.println(e);     
        public void actionPerformed(ActionEvent evt) {
           s.send(hi);
    }When I complie the program, the 5 errors would be happened. In addition, "s" isn't defination. But I don't understand what can I do. Would you mind help me? Thanks for you help.
    In addition, we assume that the class "Information" would be written with toString method.
    Billy

    Thanks for your reply.
    The errors of the program is as following:
    Multicast.java:24: cannot resolve symbol
    symbol : class ActionEvent
    location: class Multicast
    public void actionPerformed(ActionEvent evt) {
    ^You need to import ActionEvent.
    event.ActionListener is abstract; cannot be
    instantiated
    ActionListener taskPerformer = new
    ActionListener();
    ^You should not instantiate ActionListener, you should Instantiate your class instead (the class that implements ActionListener)
    symbol : variable hi
    location: class Multicast
    s.send(hi);
    ^
    st.java:25: cannot resolve symbol
    symbol : variable s
    location: class Multicast
    s.send(hi);
    ^
    4 errors
    Thanks for your help.hi and s are not known within the actionPerformed method.
    Kaj

  • I am trying to send a photo in an email and the file is huge. I remember something about sending the file with less detail and therefore reducing the size.  How?

    I am trying to send a photo in an email and the file is huge.  I remember something about reducing the size of the file but of course can't remember how.

    Use a utility such as Graphic Converter to  change the image to a jpeg using options to reduce the size of the converted image.

Maybe you are looking for