私のコードはこれです
try
{
//Connect to the login server
socket = new Socket(hostName , 15000);
out = new ObjectOutputStream(socket.getOutputStream());
input = new ObjectInputStream(socket.getInputStream());
.. //perform the login , if the login succeed make answ=1;
}
catch (UnknownHostException e) {
System.err.println("Unknown host: " + hostName);
StatusLabel.setText("Unknown host");
}
catch (ConnectException e) {
System.err.println("Connection refused by host: " + hostName);
StatusLabel.setText("Connection refused by host, server is down.");
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try
{
//Finaly closing the connection
socket.close();
System.out.flush();
System.out.println("Socket Closed");
//closing the output and input stream
out.close();
input.close();
setVisible(false); //closing the window
}
catch (IOException e ) {
System.out.println("Couldn't close socket");
}
}
if(answ==1) //if the login suceed start the class for the game
{
Gumoku_Graphics g = new Gumoku_Graphics();
g.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
g.Play();
}
Gumoku_Graphics() 内で、ゲームサーバーとの接続を実行するこのクラスを呼び出します
Game n = new Game();
status=n.Connection();
これは
public int Connection()
{
try {
socket = new Socket(hostName, 15432);
System.out.println("socket ok\n");
out = new ObjectOutputStream(socket.getOutputStream());
System.out.println("out ok\n");
input = new ObjectInputStream(socket.getInputStream());
System.out.println("socket,out,input ok\n");
return 1;
}
catch (UnknownHostException e) {
System.err.println("Unknown host: " + hostName);
return 0;
}
catch (ConnectException e) {
System.err.println("Connection refused by host: " + hostName);
return 0;
}
catch (IOException e) {
e.printStackTrace();
return 0;
}
}
そして、「input = new ObjectInputStream(socket.getInputStream());」で停止するたびに これを行うことができず、そこで立ち往生しました。「socket ok」、「out ok」と表示され、そこにスタックします。どうしたの?私は何を間違っていますか?