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

📄 socketclientb.java

📁 文件为java程序
💻 JAVA
字号:
package org.hsuper;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketClientB {

	/**
	 * @param args
	 */
	
	private static final String KB="---hello world---";
	String host="localhost";
	//int port=5001;
	Socket socket=null;
	private ServerSocket serverSocket=null;
	private int Rport=6000;
	private InputStream is=null;
	private InputStreamReader isr=null;
	private BufferedReader br=null;
	private String KS="";
	
	
	public SocketClientB()throws IOException{
		serverSocket=new ServerSocket(Rport);
	}
	public void service()
	{
		while(true)
		{
			Socket Rsocket=null;
			try {
				Rsocket=serverSocket.accept();
				is=Rsocket.getInputStream();
				isr=new InputStreamReader(is);
				br=new BufferedReader(isr);
				String read="";
				String message="";
				while((read=br.readLine())!=null)
				{
					System.out.print(read+"\n");
					message+=read;
				}
				String msg[]=message.split(";");
				KS=StringUtils.decrypt(msg[0],KB);
				String remsg=StringUtils.decrypt(msg[1],KS);
				//System.out.print(msg[0]+"\n"+msg[1]);
				//KS=StringUtils.decrypt(msg[0],msg[1]);//StringUtils.decrypt(msg[1],msg[1]));
				System.out.print("KS:"+KS+"  remsg:"+remsg);
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				if(Rsocket!=null)
					try {
						br.close();
						isr.close();
						is.close();
						Rsocket.close();
						//serverSocket.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		}
	}
	
	/*public void send()
	{
		KA=StringUtils.getPASSWORD_CRYPT_KEY();
		try {
			socket=new Socket(host,port);
			OutputStream os=socket.getOutputStream();
			os.write(KA.getBytes());
			os.close();
			service();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(socket!=null)
				try {
					socket.close();
					//serverSocket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

	}*/
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			SocketClientB sc=new SocketClientB();
			sc.service();
			//sc.send();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

⌨️ 快捷键说明

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