网络编程基本操作 网络编程基本操作
ServerSocket serverSocket = new ServerSocket(8089); int localPort = serverSocket.getLocalPort(); Socket socket = new Socket("127.0.0.1", 8089); SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress(); Socket accept = serverSocket.accept(); byte[] by = {1, 2, 3, 4, 5, 6}; OutputStream outputStream = socket.getOutputStream(); outputStream.write(by); InputStream inputStream = accept.getInputStream(); int available = inputStream.available(); for (int i = 0; i < available; i++) { System.out.println(inputStream.read()); }