Problem Writing on Sockets

hi,
I wanna to read a file from hard disk and want to write in socket so the other application can read the same file from the socket. Please help me in this case. If you have some code then kindly attach it also.
Thanks

hi there!
regarding sockets have a look at this:
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets-p2.html
pascal

Similar Messages

  • Problems writing text on Photoshop CC

    I am having problems writing text on Photoshop CC - the image goes black.

    Windows 8?  Update your video card driver from the GPU maker's website. If you cannot update your driver (like on a locked laptop machine), then set the GPU drawing mode in Photoshop to "Basic" and relaunch the app.

  • Facing problem in creating socket in a method from an already deployed application exe while same method is working from another exe from same environment from same location.

    Dll Created In: - MFC VC
    6.0
    Application Exe Developed In:
    - VC 6.0, C# and VB.net (Applications which are using dll)
    OS: - Windows XP sp2 32bit
    / Windows Server 2008 64 bit
    Problem: - Facing problem in creating socket
    in a method from an already deployed application exe while same method is working from another exe from same environment from same location.
    Description: - We have product component which
    has an exe component and from exe we invoke a method, which is defining in dll, and that dll is developed in MFC VC6.0. In the dll we have a method which downloads images from another system after making socket connection. But every time we are getting Error
    code 7, it is not giving desire result while same method is working from another exe from same environment from same location. And also me dll is deployed on many systems and giving proper output from same application.
    Already Attempt: - Because error is coming on
    client side so what we did, we created a driver in C# which invokes same method from same environment(on client machine) using same dll and we are astonished because it worked fine there.
    Kindly Suggest: -
    We are not able to figure out root cause because nothing is coming in windows event logs but what I did, for finding the problem line, I wrote logs on each line and found the exact line in application exe which is not working,
    actually  it is not executing Create () method,
    I will give snippet of the code for understanding the problem because we are not finding any kind solution for it.
    Kindly assist us in understanding and fixing this problem.
    Code Snippet: -
    Int Initialize (LPTSTR SiteAddress, short PortId)
    try
    CClientTSSocket *m_pJtsSockto;
    m_pJtsSockto = new CClientTSSocket;
    LONG lErr = m_pJtsSockto->ConnectTS(csIPAddress,PortId);
    ErrorLog (0, 0, "--------ConnectTS has been called ------------","" );
    catch(...)
    DWORD errorCode = GetLastError();
    CString errorMessage ;
    errorMessage.Format("%lu",errorCode);
    ErrorLog (0, 0, "Image System", (LPTSTR)(LPCTSTR)errorMessage);
    return  IS_ERR_WINDOWS;
    Note: -
    CClientTSSocket extends CAsyncSocket
     IS_ERR_WINDOWS is a macro error code which value I found 7.
    LONG ConnectTS(CString strIP, UINT n_Port)
    ErrorLog(0,0,"ConnectTS is calling Create [is going to call]","");
    if(!Create())
    ErrorLog(0,0,"ConnectTS is calling [Create not called successfully] ","");
     n_Err = GetLastError();
     ErrorLog(n_Err,0,"ConnectTS is calling1111111111111111Erorrrrrrrrrrrrr","");
    return NET_INIT;
    ErrorLog(0,0,"ConnectTS is calling2222222222222222222","");
    if(!AsyncSelect(0))
    n_Err = GetLastError();
    return NET_INIT;
    if(!Connect(strIP,n_Port))
    n_Err = GetLastError();
    ErrorLog(n_Err,0,"ConnectTS","");
    return SERVER_NOT_CONNECTED;
    Code description: -
    From
    int GETImage_MT() method we call Initialize() method and pass client machine IP and Port and there we call
    ConnectTS() method, In this method we Create() method and finally it returns the error code as mention in macro 7.
    Logs after running the program: -
    --------ConnectTS has been called ------------
    ConnectTS is calling Create [is going to call]
    Image System 
    0
    Note: - According to logs, problem is coming in Create method().
    Here 0 is errorMessage received in catch block. And from catch block it returns macro value 7. And when we run same method individually from same machine, same environment through same dll
    from different exe, it is working fine and we are facing any kind of problem. While same problem application was working properly earlier but now continuously it showing problem.
     Kindly assist us to resolve the issue.

    Pointer variable was already initialized; I have mention in code; kindly assist us.
    Dll Created In: - MFC VC 6.0
    Application Exe Developed In: - VC 6.0, C# and VB.net (Applications which are using dll)
    OS: - Windows XP sp2 32bit / Windows Server 2008 64 bit
    Problem: - Facing problem in creating socket
    in a method from an already deployed application exe while same method is working from another exe from same environment from same location.
    Description: - We have product component
    which has an exe component and from exe we invoke a method, which is defining in dll, and that dll is developed in MFC VC6.0. In the dll we have a method which downloads images from another system after making socket connection. But every time we are getting
    Error code 7, it is not giving desire result while same method is working from another exe from same environment from same location. And also me dll is deployed on many systems and giving proper output from same application.
    Already Attempt: - Because error is coming
    on client side so what we did, we created a driver in C# which invokes same method from same environment (on client machine) using same dll and we are astonished because it worked fine there.
    Kindly Suggest:
    - We are not able to figure out root cause because nothing is coming in windows event logs but what I did, for finding the problem line, I wrote logs on each line and found the exact line in application exe which is not
    working, actually it is not executing Create () method, I will give snippet of the code for understanding
    the problem because we are not finding any kind solution for it. Kindly assist us in understanding and fixing this problem.
    Code Snippet: -
    Int Initialize (LPTSTR SiteAddress, short PortId)
    try
    CClientTSSocket *m_pJtsSockto;
    m_pJtsSockto = new CClientTSSocket;
    LONG lErr = m_pJtsSockto->ConnectTS(csIPAddress,PortId);
    ErrorLog (0, 0, "--------ConnectTS has been called ------------","" );
    catch(...)
                       DWORD errorCode = GetLastError();
                       CString errorMessage ;
                       errorMessage.Format("%lu",errorCode);
                       ErrorLog (0, 0, "Image System", (LPTSTR)(LPCTSTR)errorMessage);
                       return  IS_ERR_WINDOWS;
    Note: - CClientTSSocket extends CAsyncSocket
     IS_ERR_WINDOWS is a macro error code which value I found 7.
    LONG ConnectTS(CString strIP, UINT n_Port)
              ErrorLog(0,0,"ConnectTS is calling Create [is going to call]","");
              if(!Create())
                       ErrorLog(0,0,"ConnectTS is calling [Create not called successfully] ","");
              n_Err = GetLastError();
              ErrorLog(n_Err,0,"ConnectTS is calling1111111111111111Erorrrrrrrrrrrrr","");
                      return NET_INIT;
              ErrorLog(0,0,"ConnectTS is calling2222222222222222222","");
              if(!AsyncSelect(0))
                       n_Err = GetLastError();
                       return NET_INIT;
              if(!Connect(strIP,n_Port))
                       n_Err = GetLastError();
                       ErrorLog(n_Err,0,"ConnectTS","");
                       return SERVER_NOT_CONNECTED;
    Code description: - From int GETImage_MT() method
    we call Initialize() method and pass client machine IP and Port and there we call ConnectTS() method, In
    this method we Create() method and finally it returns the error code as mention in macro 7.
    Logs after running the program: -
    --------ConnectTS has been called ------------
    ConnectTS is calling Create [is going to call]
    Image System  0
    Note: - According to logs, problem is coming in Create method(). Here
    0 is errorMessage received in catch block. And from catch block it returns macro value 7. And when we run same method individually from same machine, same environment through same dll from different exe, it is working fine and we are facing any kind of problem.
    While same problem application was working properly earlier but now continuously it showing problem.
     Kindly assist us to resolve the issue.

  • Lost all photos on my iPhoto and get the ERROR WRITING TO DISK when trying to reload from Time Machine. iPhoto cannot import your photos because there was a problem writing to the volume containing your iPHOTO LIBRARY  . Looking for solution.

    Lost all photos on my iPhoto and get the ERROR WRITING TO DISK when trying to reload from Time Machine. iPhoto cannot import your photos because there was a problem writing to the volume containing your iPHOTO LIBRARY  . Looking for solution.

    Problems such as yours are sometimes caused by files that should belong to you but are locked or have wrong permissions. This procedure will check for such files. It makes no changes and therefore will not, in itself, solve your problem.
    First, empty the Trash, if possible.
    Triple-click anywhere in the line below on this page to select it, then copy the selected text to the Clipboard by pressing the key combination command-C:
    find ~ $TMPDIR.. \( -flags +sappnd,schg,uappnd,uchg -o ! -user $UID -o ! -perm -600 \) 2>&- | wc -l | pbcopy
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). The command may take a noticeable amount of time to run. Wait for a new line ending in a dollar sign ($) to appear.
    The output of the command will be a number. It's automatically copied to the Clipboard. Please paste it into a reply.
    The Terminal window doesn't show the output. Please don't copy anything from there.

  • Problem with the socket and the standard output stream

    Hy, I have a little problem with a socket program. It has the server and the client. The problem is that the client at one point in the program, cannot print messages in the console.
    My program does the next: the server waits connections, when a client connects to it, the server gets outputstream to the socket and writes two strings on it. Meanwhile, the client gets the inputstream to the socket and reads on it with a loop the two strings written by the server . The strings are printed by the client in the console. The problem starts here; once the read strings are printed ,I mean, after the loop, there are other System.out.println in the client but the console doesnt print anything . It curious that only when I comment on the server code the line that says: "br.readLine()" just before the catch, the client prints all the System.out.println after the loop but why?
    Here is the code:
    Server code:
    public class MyServerSocket {
    public MyServerSocket() {
    try{
    ServerSocket server= new ServerSocket(2000);
    System.out.println("servidor iniciado");
    Socket client=server.accept();
    System.out.println("Client connected");
    OutputStream os=client.getOutputStream();
    PrintWriter pw= new PrintWriter(os);
    String cadena1="cadena1";
    String cadena2="cadena2";
    pw.println(cadena1);
    pw.println(cadena2);
    pw.flush();
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    br.readLine(); //If a comment this line, the client prints after the loop, all the System.out....
    catch (IOException e) {
    // TODO: handle exception
    public static void main(String[] args) {
    new MyServerSocket
    Client code:
    public class MyClientSocket {
    public MyClientSocket () {
    try{
    Socket client= new Socket("localhost",2000);
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    String read;
    while((read=br.readLine())!=null){
    System.out.println(read);
    //These messages are not printed unless I comment the line I talked about in the server code
    System.out.println("leido");
    System.out.println("hola");
    }catch (IOException e) {
    public static void main(String[] args) {
    new MyClientSocket
    }

    You are right but with this program the loop ends. As you see, the first class, the Server, writes to the socket one text file. The second class, the client, reads the text file in his socket written by the server and writes it to a file in his machine.
    NOTE: The loop in the client ends and the server doesnt make any close() socket or shutdownOutput() .
    public class ServidorSocketFicheromio {
         public ServidorSocketFicheromio() {
    try{
         ServerSocket servidor= new ServerSocket(2000);
         System.out.println("servidor iniciado");
         Socket cliente=servidor.accept();
         System.out.println("cliente conectado");
         OutputStream os=cliente.getOutputStream();
         PrintWriter pw= new PrintWriter(os);
         File f = new File("c:\\curso java\\DUDAS.TXT");
         FileReader fr= new FileReader(f);
         BufferedReader br= new BufferedReader(fr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
         pw.flush();
         }catch (IOException e) {
         * @param args
         public static void main(String[] args) {
              new ServidorSocketFicheromio();
    public class ClienteSocketFicheromio {
         public ClienteSocketFicheromio() {
    try{
         Socket cliente= new Socket("localhost",2000);
         File f = new File("G:\\pepe.txt");
         FileWriter fw= new FileWriter(f);
         PrintWriter pw= new PrintWriter(fw);
         InputStream is=cliente.getInputStream();
         InputStreamReader isr= new InputStreamReader(is);
         BufferedReader br= new BufferedReader(isr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
              System.out.println(leido);
              System.out.println("leido");
              System.out.println("hola");
              pw.flush();
         }catch (IOException e) {
         public static void main(String[] args) {
         new ClienteSocketFicheromio();/
    }

  • Problem about TCP Socket

    I have made a File Transfer program using TCP.
    But I find a strange problem.
    The socket will be closed after sending a file.....
    Is my code wrong or the socket is this?
    Should I upload my code??

    my new version of code...
    but there are still some problems
    1.After sending file and without closing the program, the file is still occupied by the program
    2.The received file is still different from the original...
    btw, I still don't know how to put the bos outside the loop...
    I need to use the filename as a parameter of constructor of bos
      public void sendFile(final String file) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        DataOutputStream dis = new DataOutputStream(socket.getOutputStream());
                        dis.writeUTF(new File(file).getName());
                        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(file)));
                        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
                        byte[] buffer = new byte[8192];
                        int count = 0;
                        while ((count = bis.read(buffer)) != -1) {
                            bos.write(buffer, 0, count);
                            System.out.write(buffer,0,count);                       
                        System.out.println("FINISHING SENDING FILES!");
                        bos.flush();
                        bis.close();                   
                    } catch (Exception e) {
                        e.printStackTrace();
            }).start();
        public void receiveFile() {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
                        BufferedOutputStream bos;
                        DataInputStream dis =new DataInputStream( socket.getInputStream());
                        while (true) {
                            String fileName = dis.readUTF();
                            bos = new BufferedOutputStream(new FileOutputStream(new File(fileName)));
                            byte[] buffer = new byte[8192];
                            int count = 0;
                            while ((count = bis.read(buffer)) != -1) {
                                bos.write(buffer, 0, count);
                                System.out.write(buffer,0,count);                          
                            bos.flush();
                            bos.close();                    
                    } catch (Exception e) {
                        e.printStackTrace();
            }).start();
        }

  • Director 12- can't create a windows projector - problem writing file error

    I am trying to create a windows projector of a project. when I get the following error - problem writing file - file name- Can't compress file that has been modified and not saved. The file has not been modified and has been saved. Any help would be great.

    Hi.
    You say you have tried publishing to a new empty folder.  From the video I can see that the folder has table1.app in there (25 secs in) which is a Mac projector that has been published.
    Yet you have Windows Projector checkbox ticked at the start of the video.
    I publish Mac and Windows projectors to entirely seperate folders as a matter of practice.
    I call the folders "Published" and "PublishedMac" and that is where the respective projectors for each piece of software lives.
    Perhaps there is some mix up between Mac and Windows publishing that is going on because
    you are publishing both to the same folder?
    Hope this helps.
    Richie

  • Cannot import photos from camera, "problem writing to the volume"

    I recently upgraded to iPhoto 09 from iPhoto 5. While everything seemed ok in terms of Faces and Places and Events etc, today I was trying to import some photos from my camera and suddenly iPhoto 09 gave an error *"iPhoto cannot import your photos because there was a problem writing to the volume containing your iPhoto library"* somewhere mid-way through the import. I don't understand why my own internal HD would have a problem writing to.
    Luckily, I had made a bootable backup before upgrading to iLife 09, so I just booted from that external FireWire disk, opened iPhoto 5 and as usual, it imported all the photos without any issues. But I do not want to go back and forth just for importing the photos. So, Apple, please update the iPhoto 09 with necessary bug fixes.
    Has anyone else experienced this issue ? any solutions ?
    Thanks.

    Your stated problem
    I was trying to import some photos from my camera and suddenly iPhoto 09 gave an error "iPhoto cannot import your photos because there was a problem writing to the volume containing your iPhoto library" somewhere mid-way through the import.
    As I stated I have NOT seen this problem before and it is clearly a specific problem with your system not an iPhoto bug
    Then you are not watching enough. There are several reports here itself :
    http://discussions.apple.com/thread.jspa?messageID=8971388
    Issue was user had their iPhoto library on a FAT 32 formated disk - nothing at all like your personal problem
    http://discussions.apple.com/thread.jspa?threadID=1907134&tstart=0
    User was short of disk space - one of the questions I ask you since it can cause similar problems and can corrupt your library
    http://discussions.apple.com/thread.jspa?threadID=1885964&tstart=0
    Even with all of the thread jacks nothing in this long thread is like yours - these are mostly corrupted libraries and are solved by rebuilding
    http://forums.appleinsider.com/showthread.php?p=1372496
    Not on a forum that I follow - but appears to again be a FAT32 formated disk - nothing like your issue
    SInce you are mostly interested in arguing and insulting people and not in solving your problem - if you even have one e - I choose not to deal with peole with your attitude
    LN

  • Problem writing xmltab to application server

    Hi experts ,
    I have problem writing a xmltab to appliction , the file is written to application serever but with some junk at very last record and when I open it in browser I have an error
    "An invalid character was found in text content. Error processing resource 'file:///" in the end of document.
    is that due to the line break ,
    any suggestion on resolution will be great .
    below is the code .
    Thanks
    vinay

    Use the function module
    ARCHIVFILE_SERVER_TO_CLIENT
    Pass the values: as download file and destination in the respective fields.
    File to be downloaded in :(Pass the exact file name)
    PATH :                          
    SDEC01\SAPMNT\INT\HR\OUT\FMLA-20080205-0728
    and
    Destination to download the file in:
    TARGETPATH                      C:\DOCUMENTS AND SETTINGS\JILFEM\MY DOCUMENTS\FMLA-20080205-0728
    Regards,
    Jilly

  • HP Pavillion dv6-1245dx problems writing to MicroSDHC card - errors

    I've purcahsed two different brands of MicroSDHC 32GB cards. They will allow me to write 1-2GB of info before giving me an error code: 0x80070052. I was using Windows 7 and read that this was an issue that was going to be resolved in Windows 8, so I installed Windows 8 on my laptop (It's legitimate through Microsoft's MSDN program).
    I went looking for product specifications for my laptop on the HP site and it just gives this vague answer: 5-in-1 integrated Digital Media Reader for Secure Digital cards, MultiMedia cards, Memory Stick, Memory Stick Pro, or xD Picture cards.
    It doesn't specify SD, MicroSD, MicroSDHC or any variation. I am inclined to believe that the laptop doesn't support cards as large as 32GB. The largest card I've ever tried before this was an standard size 8GB SDHC, so at least I know it will handle the SDHC part. However, I have had issues with 32GB USB drives as well, where the drive gets half full and then starts having problems writing (no error codes though).
    I'd like to know if MicroSDHC cards as large as 32GB are or aren't supported before I commit to purchasing a third card. I've tried multiple adapters as well, so I know it's not 1) Me trying to stick a tiny card in a large hole, 2) poor contact between the adapter and the laptop, or 3) poor contact between the card and the adapter.
    Thank you.

    card readers are prone to problems with the internal contacts, particularly multi-card readers. If you get a card inserted a little  bit wrong it can cause it to go out. HP should warrant the problem but if you can't get relief, the expresscard multi-readers are cheap and work well. My laptop has no built in card reader so that is what I use.

  • Problem writing a segmented file to a a socket

    I have something like this:
    temp.out.writeObject("sot");
    temp.out.flush();
    temp.out.writeObject(fileName);
    temp.out.flush();
    for (int j=0;j<size;j=j+256){
                   byte[] temporary = new byte[256];
                   f.read(temporary,j,256);
                   System.out.println("J este " + j);
                   temp.out.writeObject(String.valueOf(j));
                   temp.out.flush();
                   temp.out.writeObject(temporary);
              temp.out.flush();
    temp.out.writeObject("-3");
         temp.out.flush();
    The problem is that it writes ok the "sot", it's writing ok the file name, and the first 256 bytes.
    After that the for stops at j=0. I don't get it ..

    sorry, I'm not really any good at reading other peoples code, but if it does what I think it does, here is how I do it
    int iHaveRead = 1;
              while(iHaveRead > 0){
              try {
    InBuffer = new byte[4096] ;
    iHaveRead = Sinput2.read(InBuffer, 0, 4096) ;
              } catch(IOException e) {
              System.out.println("Error on Input " + e) ;
              iHaveRead = -1 ;
              if(iHaveRead != -1){
              iToWrite = ProcData(iHaveRead) ;
              // write to Soutput
              try {
              Soutput.write(OutBuffer, 0, iToWrite) ;
    Soutput.flush() ;
    } catch(IOException e) {
              System.out.println("Error on Output " + e) ;
    iHaveRead = -1 ;
    where procData turns inbuffer to outbuffer and returns the size

  • A GUI problem when using sockets

    I have a problem with Client.java. it creates a socket to connect to a serversocket. I do this through the method "runClient()" .
    the problem is that if I call runClient from an actionlistener add to a button. here the graphics of the window will disappear and you will be stuck for reading input (input.readObject())
    On the other hand , if you call runClient automatically from the class constructor "Client()" the program will work normally.
    can anybody give me a hint what's going on?
    Why does the program blocks in the first case for input?why not the second?
    //Client.java
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Client extends JFrame
         private JTextField enter;
         private JTextArea display;
         private JButton connect;
         ObjectOutputStream output;
         ObjectInputStream input;
         String message = "";
         public Client()
              super("Client");
              Container c = getContentPane();
              enter = new JTextField();
              enter.setEnabled(false);
              enter.addActionListener(
                   new ActionListener() {
                                  public void actionPerformed(ActionEvent e)
                                       sendData(e.getActionCommand());
              c.add(enter ,BorderLayout.NORTH);
              display = new JTextArea();
              c.add(new JScrollPane(display), BorderLayout.CENTER);
              connect = new JButton("Connect");
              connect.addActionListener(
                   new ActionListener() {
                                  public void actionPerformed(ActionEvent e)
                                       //TRY THIS . . it won't work
                                       //runclient();     
              c.add(connect, BorderLayout.EAST);
              setSize(400,300);
              show();
              //This works normally
              runClient();
         public void runClient()
              Socket client;
              try
                   display.setText("attempting to connect \n");
                   client = new Socket(InetAddress.getByName("127.0.0.1"),3500);
                   display.append("connected to : " + client.getInetAddress().getHostName());
                   output = new ObjectOutputStream(client.getOutputStream());
                   output.flush();
                   input = new ObjectInputStream(client.getInputStream());
                   display.append("\nGot I/O streams\n");
                   String message = "Client>>> Connection successful";
                   output.writeObject(message);
                   output.flush();
                   enter.setEnabled(true);
                   //YOU WILL GET STUCK HERE
                   do
                        try
                             message = (String) input.readObject();
                             display.append("\n" + message);
                             display.setCaretPosition(display.getText().length());
                        catch(ClassNotFoundException cnf)
                             display.append("unknown error\n");
                   } while( !message.equals("SERVER>>> TERMINATE"));/**/     
                   display.append("\nClosing Connection");
                   input.close();     
                   output.close();
                   client.close();
              catch(EOFException eof)
                   System.out.println("Server terminated connection");
              catch(IOException io)
                   JOptionPane.showMessageDialog(this,io.getMessage(),"Server Error",JOptionPane.ERROR_MESSAGE);
         private void sendData(String s)
              try
                   message = s;
                   output.writeObject("CLIENT>>> " + s);
                   output.flush();
                   display.append("\nCLIENT>>>" + s);
                   enter.setText("");
              catch(IOException e)
                   display.append("\nERROR writing object");
    }

    The problem is that you can NOT access a method between classes unless the method is static.
    THIS IS WRONG!
    public class Jack{
    private pale;
    private void GoUpHill()
    {pale = full;}
       public class Jill{
          public init()
          Jack.GoUpHill();
    }It is wrong because "private void GoUpHill()" is not declared as static.
    THIS IS CORRECT!
    public class Jack{
    private pale;
    private void GoUpHill()
    {pale = full;}
       public class Jill{
          public init()
          Jack.GoUpHill();
    }Note that "private static void GoUpHill()" is declared as static. That will work, but it will give an error because "pale" is not declared static. Obviously, you're going to need to make all your objects static... or, you could do this:
    public class Jack{
    private pale;
    private void GoUpHill()
    {pale = full;}
       public class Jill{
          public init()
          Jack jr = new Jack();
          jr.GoUpHill();
    }A new instance of the Jack class is made so you can use GoUpHill() at will. You don't need any static methods or objects if you use that method... but it might not always do what you want it do.

  • Problem in using socket streams with encryption and decryption

    Hi,
    I am developing a client/server program with encryption and decryption at both end. While sending a message from client it should be encrypted and at the receiving end(server) it should be decrypted and vice versa.
    But while doing so i got a problem if i use both encryption and decryption at both ends. But If i use only encryption at one (only outputstream) and decryption at other end(only inputstream) there is no problem.
    Here is client/server pair of programs in which i am encrypting the outputstream of the socket in client side and decrypting the inputstream of the socket in server side.
    serverSocketDemo.java
    import java.io.*;
    import java.net.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.util.*;
    import java.util.zip.*;
    class serverSocketDemo
         public static void main(String args[])
              try
              {                    //server listening on port 2000
                   ServerSocket server=new ServerSocket(2000);
                   while (true)
                        Socket theConnection=server.accept();
                        System.out.println("Connecting from local address : "+theConnection.getLocalAddress());
                        System.out.println("Connection request from : "+theConnection.getInetAddress());
                        //Input starts from here
                        Reader in=new InputStreamReader(getNetInStream(theConnection.getInputStream()),"ASCII");
                        StringBuffer strbuf=new StringBuffer();
                        int c;
                        while (true)
                             c=in.read();
                             if(c=='\n' || c==-1)
                                  break;
                             strbuf.append((char)c);     
                        String str=strbuf.toString();
                        System.out.println("Message from Client : "+str);
                        in.close();               
                        theConnection.close();
              catch(BindException e)
                   System.out.println("The Port is in use or u have no privilage on this port");
              catch(ConnectException e)
                   System.out.println("Connection is refused at remote host because the host is busy or no process is listening on that port");
              catch(IOException e)
                   System.out.println("Connection disconnected");          
              catch(Exception e)
         public static BufferedInputStream getNetInStream(InputStream in) throws Exception
              // register the provider that implements the algorithm
              Provider sunJce = new com.sun.crypto.provider.SunJCE( );
              Security.addProvider(sunJce);
              // create a key
              byte[] desKeyDataDec = "This encryption can not be decrypted".getBytes();
              DESKeySpec desKeySpecDec = new DESKeySpec(desKeyDataDec);
              SecretKeyFactory keyFactoryDec = SecretKeyFactory.getInstance("DES");
              SecretKey desKeyDec = keyFactoryDec.generateSecret(desKeySpecDec);
              // use Data Encryption Standard
              Cipher desDec = Cipher.getInstance("DES");
              desDec.init(Cipher.DECRYPT_MODE, desKeyDec);
              CipherInputStream cin = new CipherInputStream(in, desDec);
              BufferedInputStream bin=new BufferedInputStream(new GZIPInputStream(cin));
              return bin;
    clientSocketDemo.java
    import java.io.*;
    import java.net.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.util.*;
    import java.util.zip.*;
    class clientSocketDemo
         public static void main(String args[])
              try
                   Socket theConnection=new Socket("localhost",2000);
                   System.out.println("Connecting from local address : "+theConnection.getLocalAddress());
                   System.out.println("Connecting to : "+theConnection.getInetAddress());
                   //Output starts from here               
                   OutputStream out=getNetOutStream(theConnection.getOutputStream());
                   out.write("Please Welcome me\n".getBytes());
                   out.flush();
                   out.close();
                   theConnection.close();
              catch(BindException e)
                   System.out.println("The Port is in use or u have no privilage on this port");
              catch(ConnectException e)
                   System.out.println("Connection is refused at remote host because the host is busy or no process is listening on that port");
              catch(IOException e)
                   System.out.println("Connection disconnected");          
              catch(Exception e)
         public static OutputStream getNetOutStream(OutputStream out) throws Exception
              // register the provider that implements the algorithm
              Provider sunJce = new com.sun.crypto.provider.SunJCE( );
              Security.addProvider(sunJce);
              // create a key
              byte[] desKeyDataEnc = "This encryption can not be decrypted".getBytes();
              DESKeySpec desKeySpecEnc = new DESKeySpec(desKeyDataEnc);
              SecretKeyFactory keyFactoryEnc = SecretKeyFactory.getInstance("DES");
              SecretKey desKeyEnc = keyFactoryEnc.generateSecret(desKeySpecEnc);
              // use Data Encryption Standard
              Cipher desEnc = Cipher.getInstance("DES");
              desEnc.init(Cipher.ENCRYPT_MODE, desKeyEnc);
              CipherOutputStream cout = new CipherOutputStream(out, desEnc);
              OutputStream outstream=new BufferedOutputStream(new GZIPOutputStream(cout));
              return outstream;
    Here is client/server pair in which i use both encrypting outpustream and decrypting inputstream at both ends.
    serverSocketDemo.java
    import java.io.*;
    import java.net.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.util.*;
    import java.util.zip.*;
    class serverSocketDemo
         private Cipher desEnc,desDec;
         serverSocketDemo()
              try
                   // register the provider that implements the algorithm
                   Provider sunJce = new com.sun.crypto.provider.SunJCE( );
                   Security.addProvider(sunJce);
                   // create a key
                   byte[] desKeyData = "This encryption can not be decrypted".getBytes();
                   DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
                   SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
                   SecretKey desKey = keyFactory.generateSecret(desKeySpec);
                   desEnc = Cipher.getInstance("DES");
                   desEnc.init(Cipher.ENCRYPT_MODE, desKey);
                   desDec = Cipher.getInstance("DES");
                   desDec.init(Cipher.DECRYPT_MODE, desKey);               
              catch (javax.crypto.NoSuchPaddingException e)
                   System.out.println(e);          
              catch (java.security.NoSuchAlgorithmException e)
                   System.out.println(e);          
              catch (java.security.InvalidKeyException e)
                   System.out.println(e);          
              catch(Exception e)
                   System.out.println(e);
              startProcess();
         public void startProcess()
              try
                   ServerSocket server=new ServerSocket(2000);
                   while (true)
                        final Socket theConnection=server.accept();
                        System.out.println("Connecting from local address : "+theConnection.getLocalAddress());
                        System.out.println("Connection request from : "+theConnection.getInetAddress());
                        Thread input=new Thread()
                             public void run()
                                  try
                                       //Input starts from here
                                       Reader in=new InputStreamReader(new BufferedInputStream(new CipherInputStream(theConnection.getInputStream(), desDec)),"ASCII");
                                       StringBuffer strbuf=new StringBuffer();
                                       int c;
                                       while (true)
                                            c=in.read();
                                            if(c=='\n'|| c==-1)
                                                 break;
                                            strbuf.append((char)c);     
                                       String str=strbuf.toString();
                                       System.out.println("Message from Client : "+str);
                                  catch(Exception e)
                                       System.out.println("Error caught inside input Thread : "+e);
                        input.start();
                        Thread output=new Thread()
                             public void run()
                                  try
                                       //Output starts from here
                                       OutputStream out=new BufferedOutputStream(new CipherOutputStream(theConnection.getOutputStream(), desEnc));
                                       System.out.println("it will not be printed");
                                       out.write("You are Welcome\n".getBytes());
                                       out.flush();
                                  catch(Exception e)
                                       System.out.println("Error caught inside output Thread : "+e);
                        output.start();
                        try
                             output.join();
                             input.join();
                        catch(Exception e)
                        theConnection.close();
              catch(BindException e)
                   System.out.println("The Port is in use or u have no privilage on this port");
              catch(ConnectException e)
                   System.out.println("Connection is refused at remote host because the host is busy or no process is listening on that port");
              catch(IOException e)
                   System.out.println("Connection disconnected");          
              catch(Exception e)
         public static void main(String args[])
              serverSocketDemo server=new serverSocketDemo();          
    clientSocketDemo.java
    import java.io.*;
    import java.net.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import java.util.*;
    import java.util.zip.*;
    class clientSocketDemo
         private Cipher desEnc,desDec;
         clientSocketDemo()
              try
                   // register the provider that implements the algorithm
                   Provider sunJce = new com.sun.crypto.provider.SunJCE( );
                   Security.addProvider(sunJce);
                   // create a key
                   byte[] desKeyData = "This encryption can not be decrypted".getBytes();
                   DESKeySpec desKeySpec = new DESKeySpec(desKeyData);
                   SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
                   SecretKey desKey = keyFactory.generateSecret(desKeySpec);
                   desEnc = Cipher.getInstance("DES");
                   desDec = Cipher.getInstance("DES");
                   desEnc.init(Cipher.ENCRYPT_MODE, desKey);
                   desDec.init(Cipher.DECRYPT_MODE, desKey);               
              catch (javax.crypto.NoSuchPaddingException e)
                   System.out.println(e);          
              catch (java.security.NoSuchAlgorithmException e)
                   System.out.println(e);          
              catch (java.security.InvalidKeyException e)
                   System.out.println(e);          
              catch(Exception e)
                   System.out.println(e);
              startProcess();
         public void startProcess()
              try
                   final Socket theConnection=new Socket("localhost",2000);
                   System.out.println("Connecting from local address : "+theConnection.getLocalAddress());
                   System.out.println("Connecting to : "+theConnection.getInetAddress());
                   Thread output=new Thread()
                        public void run()
                             try
                                  //Output starts from here               
                                  OutputStream out=new BufferedOutputStream(new CipherOutputStream(theConnection.getOutputStream(), desEnc));
                                  out.write("Please Welcome me\n".getBytes());
                                  out.flush();
                             catch(Exception e)
                                  System.out.println("Error caught inside output thread : "+e);
                   output.start();     
                   Thread input=new Thread()
                        public void run()
                             try
                                  //Input starts from here
                                  Reader in=new InputStreamReader(new BufferedInputStream(new CipherInputStream(theConnection.getInputStream(), desDec)),"ASCII");          
                                  System.out.println("it will not be printed");
                                  StringBuffer strbuf=new StringBuffer();
                                  int c;
                                  while (true)
                                       c=in.read();
                                       if(c=='\n' || c==-1)
                                            break;
                                       strbuf.append((char)c);     
                                  String str=strbuf.toString();
                                  System.out.println("Message from Server : "+str);
                             catch(Exception e)
                                  System.out.println("Error caught inside input Thread : "+e);
                   input.start();
                   try
                        output.join();
                        input.join();
                   catch(Exception e)
                   theConnection.close();
              catch(BindException e)
                   System.out.println("The Port is in use or u have no privilage on this port");
              catch(ConnectException e)
                   System.out.println("Connection is refused at remote host because the host is busy or no process is listening on that port");
              catch(IOException e)
                   System.out.println("Connection disconnected");          
              catch(Exception e)
         public static void main(String args[])
              clientSocketDemo client=new clientSocketDemo();     
    **** I know that the CInput tries to read some header stuff thats why i used two threads for input and output.
    Waiting for the reply.
    Thank you.

    Do not ever post your code unless requested to. It is very annoying.
    Try testing what key is being used. Just to test this out, build a copy of your program and loop the input and outputs together. Have them print the data stream onto the screen or a text file. Compare the 1st Output and the 2nd Output and the 1st Input with the 2nd Input and then do a static test of the chipher with sample data (same data which was outputted), then do another cipher test with the ciphertext created by the first test.
    Everything should match - if it does not then follow the steps below.
    Case 1: IO Loops do not match
    Case 2: IO Loops match, but ciphertext 1st run does not match loop
    Case 3: IO Loops match, 1st ciphertext 1st run matches, but 2nd run does not
    Case 4: IO Loops match, both chiphertext runs do not match anything
    Case 5: Ciphertext runs do not match eachother when decrypted correctly (outside of the test program)
    Problems associated with the cases above:
    Case 1: Private Key is changing on either side (likely the sender - output channel)
    Case 2: Public Key is changing on either side (likely the sender - output channel)
    Case 3: Private Key changed on receiver - input channel
    Case 4: PKI failure, causing private key and public key mismatch only after a good combination was used
    Case 5: Same as Case 4

  • Problem writing to file

    I'm working on a program that asks for the users name. after that its supposed to pull the current date and time and print that into a file along with the users name.
    my problem is when i open the .txt file i get several characters i dont recogize and then my name at the end.
    Thanks for the help:
    public class CIS314Exam1MarkWellsFrame
    private ObjectOutputStream output;
    public void openFile()
    try
    output = new ObjectOutputStream(new FileOutputStream("guestlog.txt"));
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "You do not have access to this file");
    System.exit(1);
    public void insertName()
    try
    Date today = new Date();
    //utput.writeObject(today);
    //String name = JOptionPane.showInputDialog("Enter Name");
    String name = "Mark";
    output.writeObject(name);
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "Error writing to file");
    return;
    public void closeFile()
    try
    if(output !=null)
    output.close();
    catch(IOException ioException)
    JOptionPane.showMessageDialog(null, "Error Closing File");
    System.exit(1);
    System.exit(0);
    }

    This isnt the correct forum for this question. Use tags when posting code.  Post the contents of the .txt file and what unexpected characters you are getting.                                                                                                                                                                                                                                                                                                                                           

  • Problem writing meta data changes in xmp in spite of enabled settings

    Dear Adobe Community
    After struggling with this for two full days and one night, you are my last hope before I give up and migrate to Aperture instead.
    I am having problems with Lightroom 5 writing meta data changes into xmp and including development settings in JPEG, inspite of having ticked all three boxed in catalog settings.
    In spite of having checked all boxes, Lightroom refused to actually perform the actions. I allowed the save action to take a lot longer than the saving indicator showed was needed, but regardless of this no edits made in the photo would be visible outside Lightroom. I also tried unticking and ticking and restarting my compute.
    Therefore, I uninstalled the program and the reinstalled it again (the trial version both times). I added about 5000 images to Lightroom (i.e. referenced). After having made a couple of changes for one photo in development settings, I tried closing the program. However, then this message was then displayed:
    I left the program open and running for about 5-5 hours, then tried closing the program, but the message still came up so I closed the program and restarted the computer. I tried making changes to another photo, saving and then closing and the same message comes up. The program also becomes unresponsive, and of course still no meta data has been saved to the photo, i.e. when opening it outside Lightroom, the edits of the photos is not shown.
    What do do? I would greatly appreciate any insights, since I have now completely hit the wall.
    Oh yes, that´s right:
    What version of Lightroom? Include the minor version number (e.g., Lighroom 4 with the 4.1 update).
    Lightroom 5.3
    Have you installed the recent updates? (If not, you should. They fix a lot of problems.)
    I installed the program two days ago and then for the second time today.
    What operating system? This should include specific minor version numbers, like "Mac OSX v10.6.8"---not just "Mac".
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
    What kind(s) of image file(s)? When talking about camera raw files, include the model of camera.
    JPEG
    If you are getting error message(s), what is the full text of the error message(s)?
    Please see screen dumps above
    What were you doing when the problem occurred?
    Trying to save metadata + trying to open images that it seemed I had saved meta data to
    Has this ever worked before?
    No
    What other software are you running?
    For some time Chrome, Firefox, Itunes. Then I closed all other software.
    Tell us about your computer hardware. How much RAM is installed?  How much free space is on your system (C:) drive?
    4 GB 1333 MHz DDR3
    Has this ever worked before?  If so, do you recall any changes you made to Lightroom, such as adding Plug-ins, presets, etc.?  Did you make any changes to your system, such as updating hardware, printers or drivers, or installing/uninstalling any programs?
    No, the problems have been there all the time.

    AnnaK wrote:
    Hi Rob
    I think you succeeded in partly convincing me. : ) I think I will go for a non-destrucitve program like LR when I am back in Sweden, but will opt for a destructive one for now.  Unfortuntately, I have an Olypmus- so judging from your comment NX2 might not be for me.
    Hi AnnaK (see below).
    AnnaK wrote:
    My old snaps are JPEG, but I recently upgraded to an Olympus e-pl5 and will notw (edited by RC) start shooting RAW.
    Note: I edited your statement: I assume you meant now instead of not.
    If you start shooting raw, then you're gonna need a raw processor, regardless of what the next step in the process will be. And there are none better for this purpose than Lightroom, in my opinion. As has been said, you can export those back to Lightroom as jpeg then delete the raws, if storage is a major issue, or convert to Lossy DNG. Both of those options assume you're willing to adopt a non-destructive workflow, from there on out anyway (not an absolute requirement, but probably makes the most sense). It's generally a bad idea to edit a jpeg then resave it as a jpeg, because quality gets progressively worse every time you do that. Still, it's what I (and everybody else) did for years before Lightroom, and if you want to adopt such a workflow then yeah: you'll need a destructive editor that you like (or as I said, you can continue to use Lightroom in that fashion, by exporting new jpegs and deleting originals - really? that's how you want to go???). Reminder: NX2 works great on jpegs, and so is still very much a candidate in my mind - my biggest reservation in recommending it is uncertainty of it's future (it's kinda in limbo right now).
    AnnaK wrote:
    Rob Cole wrote:
    There is a plugin which will automatically delete originals upon export, but relying on plugins makes for additional complication too.
    Which plugin is this?
    Exportant (the option is invisible by default, but can be made visible by editing a text config file). To be clear: I do not recommend using Exportant for this purpose until after you've got everything else setup and functioning, and even then it would be worth reconsidering.
    AnnaK wrote:
    Rob Cole wrote:
    What I do is auto-publish to all consumption destinations after each round of edits, but that takes more space.
    How do you do this?
    Via Publish Services.
    PS - I also use features in 'Publish Service Assistant' and 'Change Manager' plugins (for complete automation), but most people just select publish collections and/or sets and click 'Publish' - if you only have a few collections/services it's convenient enough.
    AnnaK wrote:
    Would you happen to have any tips on which plugins I may want to use together with Photoshop Elements?
    No - sorry, maybe somebody else does.
    Did I get 'em all?
    Rob

Maybe you are looking for

  • Messages: One MacBook, One User Account, Two Users?? Help!

    Hi, I just upgraded to Mountain Lion on my MBA from mid 2011 - so far so good! In our home, my wife and I have one Mac that we both use. Since we use it most of the time to browse on the Internet, listen to music, looking at pictures e.g. we only hav

  • My HP Officejet 6500A WIll not print in Color

    Hi, I have a HP Officejet 6500A wireless printer. I changed all of the color cartridges, and now cannot get it to pront any colors at all. ANy feedback will be appreciated.

  • Installing latest showing wrong version in registry

    I installed the latested install_flash_player_11_active_x.msi from the flash player distribution page.  The version on the computer I installed was reporting as 11.3.300.270.  After installation, if I went to http://www.adobe.com/software/flash/about

  • Still got questions regarding iPhone 4 signal.?

    Ok buying a new iPhone tomorrow, currently, have the 3GS, which am quiet happy with, but am in a complex situation, with vodafone uk, wereby, I need to decide within 7 days, whether to choose an iPhone 4 or something else. Now the only worry I have i

  • MPEG 2 failure on compressor export

    I Have recently changed from using  single layer DVD to dual layer DVD and I've got some great results Using the send to compressor route and changing bit rates to suit. however after about 4 successful projects burnt to DVD I'm now getting failures