public class JavaApplication15 {
public static String ip="127.0.0.1";
public static int port=5060;
public static void main(String[] args) throws IOException {
ServerSocket ss = null;
InetAddress ii = InetAddress.getLocalHost();
System.out.println(ii);
InetAddress ad = InetAddress.getByName(ip);
System.out.println(ad);
InetAddress i = ad;
System.out.println(i);
try {
// TODO code application logic here
ss = new ServerSocket();
ss.bind(new InetSocketAddress(ip, port));
InetSocketAddress ia;
String st=ss.getLocalSocketAddress().toString(); // print socket ip and address
System.out.println(st);
System.out.println("created");
} catch (IOException ex) {
System.out.println("not created");
}
Socket client = null,ee = null;
client = ss.accept();
PrintWriter out = null;
BufferedReader in = null ;
out = new PrintWriter(client.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String input = null;
while((input = in.readLine())!=null){
System.out.println(input);
System.out.println("echo :" +in.readLine());
}
out.flush();
in.close();
stdin.close();
client.close();
ss.close();
}
}
}
在此代码服务器中正在创建并尝试与套接字建立连接。我认为这段代码应该显示输出,但它没有显示。例如:如果我在控制台中打招呼,它应该打印你好。但事实并非如此。任何人都可以帮助我实际发生的事情???