Java Send custom object via socket Client, Server, LAN
<p>I want to send object (custom class) via socket from Client to Server. This is my code:</p>

<p><strong>Server:</strong></p>

<pre><code>private class SocketServerThread extends Thread {

    @Override
    public void run() {
        try {
            serverSocket = new ServerSocket(socketServerPORT);

            while (true) {
                clientSocket = serverSocket.accept();
                ObjectInputStream inObject = new ObjectInputStream(
                        clientSocket.getInputStream());
                try {
                    Te xxx = (Te) inObject.readObject();

                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }


                //DataInputStream dataInputStream = new DataInputStream(
                        //clientSocket.getInputStream());
                //messageFromClient=dataInputStream.readUTF();

        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //activity.msgFromC.setText(messageFromClient);
            }
        });
    }
}
</code></pre>

<p><strong>Client:</strong></p>

<pre><code>public Client(String aIPaddres, int aPort, Te u) {
    AddressIP = aIPaddres;
    Port = aPort;
    sendUser = u;
}
protected Void doInBackground(Void... arg0) {

    Socket clientSocket = null;

    try {

        clientSocket = new Socket(AddressIP, Port);
        ObjectOutputStream outObject = new ObjectOutputStream(
                clientSocket.getOutputStream());
        outObject.writeObject(sendUser);
        //DataOutputStream daneWyjsciowe = new DataOutputStream(
                //clientSocket.getOutputStream());
        //daneWyjsciowe.writeUTF("Czesc!" );

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        //response = "UnknownHostException: " + e.toString();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        //response = "IOException: " + e.toString();
    } finally {
        if (clientSocket != null) {
            try {
                clientSocket.close();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return null;

}
</code></pre>

<p><strong>Custom class (Te.class):</strong></p>

<pre><code>public class Te implements Serializable {
public String message;
public Te(String m){
    message=m;
}
</code></pre>

<p>}</p>

<p>When I passing simple data i.e. String there is no problem. But now I want to pass object, but there is always ClassNotFoundException at server. I read lot of stacks but I didnt find answer. Could U help me?</p>