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

📄 tcpserverb.java

📁 培训的时候的代码
💻 JAVA
字号:
package day15;
import java.io.*;
import java.io.IOException;
import java.net.*;
public class TCPServerB {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ServerSocket ss=null;
		Socket s=null;
		BufferedReader br=null;
		PrintStream ps=null;
		try {
			ss=new ServerSocket(8887);
			while(true){
				s=ss.accept();
				br=new BufferedReader(new InputStreamReader(s.getInputStream()));
				String str=br.readLine();
				System.out.println(s.getInetAddress()+":");
				str=str.toUpperCase();
				ps=new PrintStream(s.getOutputStream());
				ps.println(str);
				ps.flush();
			}
		} catch (IOException e) {
			
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			if(br!=null)
				try {
					br.close();
				} catch (IOException e1) {
					
					e1.printStackTrace();
				}
			if(s!=null)
				try {
					s.close();
				} catch (IOException e) {
					
					e.printStackTrace();
				}
			if(ss!=null){
				try {
					ss.close();
				} catch (IOException e) {
					
					e.printStackTrace();
				}
			}
		}

	}

}

⌨️ 快捷键说明

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