tcpip.java
来自「用JAVA编网页编程示例」· Java 代码 · 共 103 行
JAVA
103 行
//---------------------------------------------------------------------------- //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 + =
减小字号Ctrl + -
显示快捷键?