0

i'm try to create a simple client/server java application; I have to send a java object throw a socket ... this is the code:
client:

    package performancethinclient;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;


public class PerformanceThinClient 
{
    public static void main(String[] args)
    {
       startClient("localhost");
    }
   static void startClient(String HOST) 
    {
        try 
        {

                Socket clientSocket = new Socket(HOST, 50000);
                // Create the input & output streams to the server
                ObjectInputStream inFromServer = new ObjectInputStream(clientSocket.getInputStream());

                Rilevazione rl=(Rilevazione) inFromServer.readObject();
                inFromServer.close();
                clientSocket.close();          

                rl.printit();

        }
        catch (IOException | ClassNotFoundException e)
        {
            System.err.println("Client Error: " + e.getMessage());
            System.err.println("Localized: " + e.getLocalizedMessage());
            System.err.println("Stack Trace: " + e.getStackTrace());
        }
    }
}

server:

    import java.io.*;
import java.net.Socket;
import java.net.ServerSocket;
public class PerformanceServer 
{

    public static void main(String args[]) throws IOException, InterruptedException
    {
            StartServer();
        }

    public static void StartServer()
    {
        try 
            {
                ServerSocket welcomeSocket = new ServerSocket(50000);

                while (true) 
                {    
                    // Create the Client Socket
                    Socket client = welcomeSocket.accept();
                    System.out.println("Socket Extablished...");
                    // Create input and output streams to client
                    ObjectOutputStream outToClient = new ObjectOutputStream(client.getOutputStream());
                    ObjectInputStream inFromClient = new ObjectInputStream(client.getInputStream());

                    Rilevazione rl=new Rilevazione();
                    outToClient.writeObject(rl);        
                    System.out.println("Object Send");
                }

            }
            catch (Exception e) 
            {
                System.err.println("Server Error: " + e.getMessage());
                System.err.println("Localized: " + e.getLocalizedMessage());
                System.err.println("Stack Trace: " + e.getStackTrace());
                System.err.println("To String: " + e.toString());
            }

    }
}

Rilevazione is a java class that i have create in the same folder .
the code:

    package performancethinclient;

import java.io.IOException;
import java.util.*;

public class Rilevazione 
{
    Date DataOra;
    GeneralInfo GeneralInformation ;
    CPU ControlProcessingUnit;
    RAM RandomAccessMemory;
    HDD HardDrive;
    Apache apache;
    public Rilevazione() throws IOException, InterruptedException
    {
         DataOra = new Date();
        GeneralInformation=new GeneralInfo();
        ControlProcessingUnit=new CPU();
        RandomAccessMemory=new RAM();
        HardDrive=new HDD();
        apache=new Apache();

    }
    public void printit()
    {
        System.out.println("--------------------------------GENERAL INFORMATION------------------------------------------");
        System.out.println("----BIOS");
        System.out.println(this.GeneralInformation.BIOS);

    }

}

now the Class Rilevazione is present in both application(client and server) in src folder where there are .java files and then Rilevazione.java My problem is about sending object throw socket ... javac compiler does not work , the error occured is in the cast of Rilevazione

Rilevazione rl=(Rilevazione) inFromServer.readObject();

it can't compile when in the folder i type: javac PerformanceThinClient.java Can anyone help me? Thank's

5
  • Okay, now I cant understand you...you said in stackoverflow.com/questions/40461714/… that it was compiling, but not running as you expected... =/ Commented Nov 7, 2016 at 12:58
  • Yes it compile but doesn t run property Commented Nov 7, 2016 at 13:03
  • So, please, read How to create a Minimal, Complete, and Verifiable example. You are saying in this question that you are not even compiling your code, but you are! Ask better to get better asnwers..say what is really happening and what you expected Commented Nov 7, 2016 at 13:05
  • It complie ... But i can t understand why it cant with a simple javac PerformanceThinClient... Commented Nov 7, 2016 at 13:31
  • Please, see this: stackoverflow.com/questions/10475491/… Commented Nov 7, 2016 at 13:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.