Mam problem, otóż stworzyłem sobie Serializowaną klasę którą chcę wyslać z serwera do klienta :
import java.io.*;
public class Data implements Serializable{
int X;
int Y;
int xEnd;
int yEnd;
int Action;
public Data(int X, int Y, int xEnd, int yEnd, int Action)
{
this.X = X;
this.Y = Y;
this.xEnd = xEnd;
this.yEnd = yEnd;
this.Action = Action;
}
public int getX() {
return X;
}
public int getY() {
return Y;
}
public int getxEnd() {
return xEnd;
}
public int getyEnd() {
return yEnd;
}
public int getAction() {
return yEnd;
}
public void setX(int X) {
this.X = X;
}
public void setY(int Y) {
this.Y = Y;
}
public void setxEnd(int xEnd) {
this.xEnd = xEnd;
}
public void setyEnd(int yEnd) {
this.xEnd = yEnd;
}
public void setAction(int Action) {
this.Action = Action;
}
public Data() {
System.out.println("wywołanie bezparametrowego konstruktora klasy Adres");
}
}
I dalej odpowiednie buttony uruchamiające połączenie w serwerze :
private void StartActionPerformed(java.awt.event.ActionEvent evt) {
try
{
ServerSocket server = new ServerSocket(8000);
Socket channel = server.accept();
objOut = new ObjectOutputStream(channel.getOutputStream());
objIn = new ObjectInputStream(channel.getInputStream());
Draw = new Data();
} catch(Exception d) {System.out.println("Elo");}
}
I w kliencie :
private void StartActionPerformed(java.awt.event.ActionEvent evt) {
try{
Socket client = new Socket("localhost", 8000);
objIn = new ObjectInputStream(client.getInputStream());
objOut = new ObjectOutputStream(client.getOutputStream());
Draw = new Data();
} catch (Exception a) {System.out.println("BladKlient");}
}
I teraz w odpowiednim buttonie w Kliencie, odbieram sobie Obiekt od serwera ale ciagle wyrzuca mi tutaj wyjątek, nie wiem dlaczego, dodam że serwer normalnie nawiązuje połączenie i wysyła Obiekt. Wyjątek wyrzuca dopiero gdy czytam w kliencie :
private void ReceiveActionPerformed(java.awt.event.ActionEvent evt) {
try {
Draw = (Data) objIn.readObject();
}
catch (Exception e ) {e.printStackTrace();}
}
Nie mogę znaleźć przyczyny, jakieś pomysły ? :P