客户端程序发送每次猜的数字
package test;
import javaio*;
import javanet*;
public class ClientApp {
private Socket socket;
private BufferedReader netIn;
private PrintWriter netOut;
private BufferedReader keyboardIn;
xxxx
static Boolean finished = false;
public ClientApp() throws IOException {
Systemoutprintln(请输入服务器地址连接本地服务器请输入localhost);
keyboardIn = new BufferedReader(new InputStreamReader(Systemin));
try {
if (keyboardInreadLine()equalsIgnoreCase(localhost)) {
socket = new Socket(InetAddressgetLocalHost() ServerAppPORT);
} else {
socket = new Socket(InetAddressgetByName(keyboardInreadLine()) ServerAppPORT);
}
netIn = new BufferedReader(new InputStreamReader(socketgetInputStream()));
xxxx
netOut = new PrintWriter(socketgetOutputStream());
} catch (UnknownHostException e) {
Systemerrprintln(连接不到服务器);
Systemexit();
}
Systemoutprintln(连接成功);
while (!finished) {
Systemoutprintln(请输入-之间的数字);
netOutprintln(keyboardInreadLine());
netOutflush();
String str = netInreadLine();
if (str == null) {
finished = true;
xxxx
break;
}
Systemoutprintln(str);
if (strstartsWith(OK)) {
finished = true;
break;
}
}
netInclose();
netOutclose();
keyboardInclose();
socketclose();
}
public static void main(String[] args) throws IOException {
new ClientApp(); xxxx
}
}
[] []