高分悬赏:Java语言如何调用net send发送聊天消息到网上邻居的计算机(window作业系统)

高分悬赏:Java语言如何调用net send发送聊天消息到网上邻居的计算机(window作业系统)

现在Windows 系统没有"net send"命令了,改为"msg"了。
Java 通过Runtime接口来调用系统功能实现。

 Runtime run = Runtime.getRuntime();
 Process pr = run.exec( "net send ip msg" );
 pr.waitFor();

1、如果知道对方的IP就好办
2、
private static String mSendMsg;
public static void StartSendToServer(String s) {
mSendMsg = s;
new Thread(new Runnable() {
@Override
public void run() {
SendToServer();
}
}).start();

}

public static void SendToServer() {
    try {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("192.168.31.116", 8888), 5000);
        if (socket.isConnected()) {
            socket.getOutputStream().write(mSendMsg.getBytes());
            socket.getOutputStream().flush();
            Thread.sleep(10000);
            socket.close();
        } else {
            Log.i("xw", "failed to connect server");
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.i("xw", e.toString());
    }
    mSendMsg = "";
}