⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.java

📁 JAVA语言编写的简单服务器与客服端的通信代码 包括Server.java和Client.java。 可实现两台主机间的通信
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class Server extends JFrame {

	/**
	 * @param args
	 */
	private JTextArea jta=new JTextArea();
	public Server()
	{
                this.setTitle("Server");
		this.setSize(350,250);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setLayout(new BorderLayout());
		add(new JScrollPane(jta),BorderLayout.CENTER);
		try{
			ServerSocket serversocket=new ServerSocket(8000);
			jta.append("Server started at "+new Date()+'\n');
			Socket socket=serversocket.accept();
			DataInputStream inputt=new DataInputStream(socket.getInputStream());
			DataOutputStream outt=new DataOutputStream(socket.getOutputStream());
			while(true)
			{
				double radius=inputt.readDouble();
				double area=radius*radius*Math.PI;
				outt.writeDouble(area);
				jta.append("Radius recived from client: "+radius+'\n');
				jta.append("Area found: "+area+'\n');
			}
		}
		catch(IOException ex){}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Server server=new Server();
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -