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

📄 tcpip.java

📁 用JAVA编网页编程示例
💻 JAVA
字号:
//---------------------------------------------------------------------------- //head.oak //import java.applet.Applet;//import java.awt.image.*;//import java.awt.*;import java.net.*;import java.util.*;import java.io.*;import java.*;public class tcpip{	protected Socket s;	public DataInputStream dis;	protected DataOutputStream dos;	protected int buffer= 124;	protected int dlength = 124;				public synchronized void disconnect(){}			public synchronized void send(String given, boolean close){	send(transS(given), close);}public synchronized void send(byte[] given, boolean close){	int le= given.length;	byte[] temp= new byte[le];	for(int i= 0; i< le; i++)		temp[i]= given[i];	try	{		dos= new DataOutputStream(new BufferedOutputStream(s.getOutputStream()));		dos.write(temp, 0, temp.length);		dos.flush();		if(close)			dos.close();	}	catch(Exception ex)	{	    System.out.println("Error sending data : " + ex.toString());	}}public synchronized byte[] receive(boolean close){	byte[] retval= new byte[0];	try	{   
					dis= new DataInputStream(new BufferedInputStream(s.getInputStream()));
		if (dis.available ()!=0) {
		retval= new byte[dis.available()];		dis.read(retval);
		}		if(close)			dis.close();	}	catch(Exception ex)	{	System.out.println("Error in receive exception Routine");	} 	return(retval);}public synchronized char rec(boolean close){	byte retval[]= new byte[1];	try	{		boolean rec_data = false;		dis= new DataInputStream(new BufferedInputStream(s.getInputStream()));		while((rec_data == false)&&(close == false)){			if(dis.available()!=0)				rec_data = true;		}					retval= new byte[dis.available()];		dis.read(retval);		if((char)retval[0] == 0x1B)		dis.close();	}	catch(Exception ex)	{		System.out.println("Error in receive exception Routine");	}	return((char)retval[0]);}public tcpip(Socket _given){	s= _given;
	
		}public byte[] transS(String given){	int length= given.length();	byte[] retvalue= new byte[length];	given.getBytes(0, length, retvalue, 0);	return(retvalue);    }}

⌨️ 快捷键说明

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