Вот код клиента:
public class ServerThread extends Thread {
private Message client;
private Socket fromServer;
private ObjectOutputStream out;
private ObjectInputStream in;
private TextView checkText;
//конструктор для регистрации
public ServerThread(Message clientSend, TextView checkText){
this.client = clientSend;
this.checkText = checkText;
start();
}
private void check() {
Message serverSend = null;
try {
out.writeObject(client);
try {
serverSend = (Message) in.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if(serverSend.getMessage()=="true"){
checkText.setText("Регистрация успешно завершена.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void run() {
try {
fromServer = new Socket("192.168.1.103", 5050);
out = new ObjectOutputStream(fromServer.getOutputStream());
in = new ObjectInputStream(fromServer.getInputStream());
if (client.getSight() == "R") check();
} catch (IOException e) {
e.printStackTrace();
}
}
}
А вот код сервера:
public class ClientThread extends Thread {
private Socket fromClient;
private Message clientSend;
private DataBase DB;
ObjectInputStream in;
ObjectOutputStream out;
public ClientThread(Socket socket) throws IOException, SQLException {
this.fromClient = socket;
DB = new DataBase("jdbc:mysql://localhost:3306/my_db", "root", "root");
in = new ObjectInputStream(this.fromClient.getInputStream());
out = new ObjectOutputStream(this.fromClient.getOutputStream());
System.out.println("Client joined");
start();
}
private void check(String login, String password) throws SQLException, IOException {
String query = "INSERT INTO testtable(LOGIN,PASSWORD)VALUES(?,?)";
PreparedStatement preparedStatement = DB.connection.prepareStatement(query);
preparedStatement.setString(1, clientSend.getLogin());
preparedStatement.setString(2, clientSend.getPassword());
preparedStatement.execute();
out.writeObject(new Message("true"));
System.err.println("Регистрация завершена обратные данные отправлены");
}
public void run() {
//Создаем потоки ввода-вывода для работы с сокетом
try {
clientSend = (Message) in.readObject();
System.out.println("run заработал");
try {
if(clientSend.getSight()=="R") {
System.out.println("метод заработал");
check(clientSend.getLogin(), clientSend.getPassword());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
System.err.print(e);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Клиент успешно подключатся к серверу но вот сообщение сервер не может получить, в чём проблема?