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

📄 socketirc.java

📁 用java实现的红外线通讯源码
💻 JAVA
字号:
/*Copyright (C) 2004  Juho Vähä-HerttuaThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/package jmirc;import java.io.*;import javax.microedition.io.*;public class SocketIrc implements IrcConnection {	private DataInputStream in;	private DataOutputStream out;	private String encoding, outbuf;	private boolean pollmode, connected;	private int bytein;	private int byteout;	public SocketIrc(boolean pollmode, String charset) {		encoding = charset;		bytein = 0;		byteout = 0;		this.pollmode = pollmode;		connected = false;	}	public String connect(String host, int port, String init) {		StreamConnection connector;		String ret = null;		try {			connector = (StreamConnection) Connector.open("socket://" + host + ":" + port, Connector.READ_WRITE);			in = connector.openDataInputStream();			out = connector.openDataOutputStream(); 			outbuf = null;			connected = true;			ret = writeData(init);		} catch (IOException ioe) {			ret = "Error trying to connect to IRC server, aborting... ";			ret += "Exception: " + ioe.getMessage();			return ret;		}		return null;	}	public void disconnect() {		if (connected) {			try {				writeData("QUIT :used jmIrc\r\n");				updateConnection();				out.flush();				out.close();				in.close();				connected = false;			}			catch(Exception e) {}		}	}		public String updateConnection() {		byte[] tmp;		String ret;		if (outbuf != null && connected) {			try {				try {					tmp = outbuf.getBytes(encoding);				} catch (UnsupportedEncodingException uee) {					tmp = outbuf.getBytes();				}				out.write(tmp);				byteout += tmp.length;				outbuf = null;			}			catch (IOException ioe) {				ret = "Error reading/writing to IRC socket, aborting... ";				ret += "Exception: " + ioe.getMessage();				connected = false;				return ret;			}		}		return null;	}	public String readLine() {		int ch;		String ret;		byte[] buf;		ret = null;		try {			buf = Utils.readLine(in);			if (buf==null) return null;			bytein += buf.length;			try {				ret = new String(buf, encoding);			} catch (UnsupportedEncodingException uee) {				ret = new String(buf);			}		} catch(IOException ioe) {			connected = false;		}		return ret;	}		public String writeData(String input) {		if (outbuf == null) outbuf = input;		else outbuf += input;		return updateConnection();	}	public boolean hasDataInBuffer() {		if (pollmode) {			try {				return (in.available() > 0);			} catch (IOException ioe) {				return false;			}		}		else return connected;	}	public boolean isConnected() {		return connected;	}	public int getBytesIn() {		return bytein;	}	public int getBytesOut() {		return byteout;	}}

⌨️ 快捷键说明

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