Socket Client = new Socket("ip", port);
private ObjectOutputStream out;
out = new ObjectOutputStream(Client.getOutputStream());//line3
out.flush();
나는 소켓 program.when 나는 문제가 없다 클라이언트가있다. 클라이언트가 둘째로이고 나중에 클라이언트 프로그램은이다 waiting
선 3.it에는 아무 과실도없고 exception.what는있다 문제? ObjectOutputStream에 서버로부터의 응답이 필요합니까?
TCP = new Thread(new Runnable() {
@Override
public void run() {
if ("TCP".equals(Protocol)) {
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
RunServer();
}
}
});
TCPWait = new Thread(new Runnable() {
@Override
public void run() {
try {
WaitForConnection();
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
TCPWait.start();
TCP.start();
public void RunServer() {
try {
while (true) {
{
accessLock.lock();
if(CanContinue == false)
condition.await();
try {
// WaitForConnection();
GetStreams();
ProcessConnection();
accessLock.unlock();
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "ارتباط قطع شد" + e.getMessage());
}
}
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e.getMessage());
}
public void WaitForConnection() throws IOException {
jTextArea1.append("لطفا تا برقرای ارتباط صبر کنید.../n ");
accessLock.lock();
connection = server.accept();
CanContinue = true;
condition.signal();
accessLock.unlock();
jTextArea1.append("ارتباط از " + connection.getInetAddress().getHostName() + "\n");
}
public void GetStreams() {
try {
Socket s = new Socket();
s = connection;
out = new ObjectOutputStream(s.getOutputStream());
out.flush();
in = new ObjectInputStream(s.getInputStream());
jTextArea1.append("در حال برقرای ارتباط...\n");
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "مشکل در برقرای ارتباط!\n");
}
}
public void ProcessConnection() {
SendData("ارتباط برقرا شد\n");
try {
jTextArea1.append((String) in.readObject() + "\n");
} catch (Exception e) {
}
String message = "";
do {
try {
jTextArea1.append((String) in.readObject() + "\n");
} catch (Exception e) {
}
} while (message != "Exit");
}
WaitForConnection()
runserver()
전송에 다른 스레드에 메시지를받는 청취자입니다.
클라이언트가 다른 자바 프로세스입니까? – Tudor
예 클라이언트는 프로그램이고 다른 하나는 서버입니다. –
그리고이 문제가 발생하면 여러 클라이언트 프로그램을 시작 하시겠습니까? – Tudor