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

📄 read_write.java

📁 java的通讯程序(socket)
💻 JAVA
字号:
/****************************************************************/
/** 模块名称:      client.java                                **/
/** 模块用途:      java的客户端通讯程序                        **/
/** 建立日期    :2003/09/27                                   **/
/** 最后修改日期:2003/09/27                                  **/
/** 模块编写人  :          蒋    浩                           ***
/****************************************************************/
/****************************************************************/
/* 变量名:                                                      */
/*      time_out             设置端口读写的超时时间             */
/*      connect()               Socket客户端主程序              */
/* 修改记录:                                                   */
/*                      2003/10/22 初稿                         */
/****************************************************************/
package Socket_java;
import java.io.*;
import java.net.*;

public class read_write
{
	static Socket socket;
	static BufferedReader in;
	static PrintWriter out;
	static Socket test;
	static read_write Time_out;
	
	public static void time_out(Socket _out,int time_second){
		int test_time=0;
		test_time=time_second*1000;
		try{
			_out.setSoTimeout(test_time);
		}catch (Exception e){
			System.out.println("----------->"+e.toString());

		}
		
	}
	
	public void read_write(){
	}

	
	public static String read_sock(Socket socket){
		String jh="";
		try{
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			jh=in.readLine();
		
		}
		catch(Exception e)
		{
			//System.out.println("read_sock error--"+e.getMessage()+"]");
			//Time_out.write_sock(socket,"test");
			//System.out.println(" time out write server is test");
			//String kkk=Time_out.read_sock(socket);
			//System.out.println("-------------------->"+kkk);
		}
			return(jh);
	}
	
	public static void write_sock(Socket socket,String buf){
		String send_type="";
		try{
			
			out = new PrintWriter(socket.getOutputStream(),true);
			out.println(buf);
			//System.out.println("i send buf="+buf);
			send_type="ok";	
		}catch(IOException e){
			System.out.println("write_sock error--"+e.getMessage()+"]");
		}
		//return(send_type);
		
	}
	
	public static String input_buf(){
		
		String s="";
		try{
			BufferedReader line = 
			
			new BufferedReader(new InputStreamReader(System.in));
			System.out.println("pleas input some words and Send to Server Port :");
			System.out.flush();
			s=line.readLine();
		return(s);
		}catch(IOException e){
			System.out.println("input_buf() error--["+e.getMessage()+"]");
		}
		return(s);
	}

}

⌨️ 快捷键说明

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