我写了一个Socket客户端和ServerSocket程序。客户端在PC1上运行,并将命令发送到第二台PC上的服务器插槽。客户端运行得很好(通过print语句确认),但是服务器到达开关的任何case语句(下面的代码)后,它将停止。我测试了print语句,它从不离开“ case x”块。它只是执行dt.browse(...)命令,然后似乎在那里停止了。这是浏览命令受阻还是我丢失了什么?
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(...);
while (true) {
Socket socket = serverSocket.accept();
DataInputStream dIn = new DataInputStream(socket.getInputStream());
byte command = dIn.readByte();
System.out.println("received command:"+command);
switch (command) {
case 1:
try
{
URI uri = new URI("https://www.google.ch/");
Desktop dt = Desktop.getDesktop();
dt.browse(uri);
}
catch(Exception ex){ex.printStackTrace();}
//Runtime.getRuntime().exec("start /max chrome google.ch");
break;