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

📄 simpleserver.java

📁 JAVA程序设计课程中各章节的程序实例。
💻 JAVA
字号:
import java.net.*;
import java.io.*;

public class SimpleServer
{
	public static void main(String args[]) throws IOException
	{
		ServerSocket S = null;
		Socket s1;

		String S_send = new String("");
		String S_recv = new String("");

		OutputStream S_out;
		InputStream S_in;

		DataOutputStream dout_S;
		DataInputStream din_S;

		try
		{
			S = new ServerSocket(5432);
		}
		catch(IOException e)
		{
			System.out.println("exception caught");
		}
		
		s1 = S.accept();
		BufferedReader b = new BufferedReader(new InputStreamReader(System.in));

		S_in = s1.getInputStream();
		din_S = new DataInputStream(S_in);
		S_out = s1.getOutputStream();
		dout_S = new DataOutputStream(S_out);

		while(!S_send.equals("Bye") && !S_recv.equals("Bye"))
		{
			try
			{
			
				S_in = s1.getInputStream();
				din_S = new DataInputStream(S_in);
				S_recv = din_S.readUTF();
				System.out.println("Client: " + S_recv);
				
				S_out = s1.getOutputStream();
				dout_S = new DataOutputStream(S_out);
				S_send = b.readLine();
				dout_S.writeUTF(S_send);
			}
			catch(IOException e)
			{
				System.out.println("exception caught 2");
			}
		}
		dout_S.close();
		din_S.close();
		S_in.close();
		S_out.close();
		s1.close();
	}
}

⌨️ 快捷键说明

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