一、服务器端
ServerSocket serverSocket = new ServerSocket(8080);//创建服务器套接字,
Socket socket = serverSocket.accept();//并等待连接
二、客户端
Socket socket = new Socket("localhost",8080);//创建套接字并通过该套接字向服务器发送请求连接
客户端代码:
public class Client extends Application{
//初始化驶入输出流
DataOutputStream outputStream = null;
DataInputStream inputStream = null;
@Override
public void start(Stage primaryStage) throws Exception {
BorderPane pane = new BorderPane();
pane.setPadding(new Insets(10,10,10,10));
pane.setLeft(new Label("输入半径: "));
TextField tf = new TextField();
tf.setAlignment(Pos.BOTTOM_LEFT);
pane.setCenter(tf);
BorderPane mainPane = new BorderPane();
TextArea ta = n