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

📄 toqfsocketmanager.java

📁 用mina框架编写的转发代理服务程序,含自动更新功能
💻 JAVA
字号:
package com.frontMachine.client;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;

import com.frontMachine.setting.RemoteHost;
import com.frontMachine.util.ErrMsg;
import com.frontMachine.util.ExceptionLoger;
import com.frontMachine.util.MACMan;
import com.frontMachine.util.StrUtil;

/**
 * @发送到清分的Socket通讯类
 * @author LRT
 * @version 1.0
 */

public class ToQFSocketManager
{
	public static byte[] send(RemoteHost destination,String msg)
	{
		Socket client = null;
		DataInputStream rtnStream = null;
		DataOutputStream out = null;
		byte[] rtnbytes=null;
		try
		{
			if(destination==null)
				return null;
			client=new Socket(destination.getIp(),destination.getPort());
			client.setSoTimeout(25000);
			int bufsize=512;
			ArrayList rtnList=new ArrayList();
			byte[] buf=new byte[bufsize];
			rtnStream=new DataInputStream(client.getInputStream());
			out = new DataOutputStream(client.getOutputStream());
			out.write(msg.getBytes());
			out.flush(); 
			int iRead=rtnStream.read(buf);
			int lastRead=0;
			while(iRead!=-1)
			{
				lastRead=iRead;
				rtnList.add(buf);
				buf=new byte[bufsize];
				iRead=rtnStream.read(buf);			
			}
			
			int rtnListSize=rtnList.size();
			if(rtnListSize==0)
				return null;	
			rtnbytes=new byte[(rtnListSize-1)*bufsize + lastRead];
			int i=0;
			for(;i<rtnListSize-1;i++)
				System.arraycopy((byte[])rtnList.get(i), 0, rtnbytes, i*bufsize, bufsize);
			System.arraycopy((byte[])rtnList.get(i), 0, rtnbytes, i*bufsize, lastRead);
			rtnList.clear();
		}
		catch(SocketException se)
		{
			String expMsg=new MACMan().countTXMAC(ErrMsg.QF_SOCKET_EXCEPTION);
			//return	 ByteBuffer.wrap(expMsg.getBytes());
			rtnbytes = StrUtil.packageXML(expMsg);
		}
		catch(SocketTimeoutException ste)
		{
			String expMsg=new MACMan().countTXMAC(ErrMsg.QF_SOCKET_TIMEOUT);
			//return	 ByteBuffer.wrap(expMsg.getBytes());	
			rtnbytes = StrUtil.packageXML(expMsg);
		}
		catch(Exception ee)
		{
			ExceptionLoger.ExLog(ee);
			String expMsg=new MACMan().countTXMAC(ErrMsg.ZF_SEND_ERROR);
			//return	 ByteBuffer.wrap(expMsg.getBytes());
			rtnbytes = StrUtil.packageXML(expMsg);
		}
		finally
		{
			try{
				rtnStream.close();
				out.close();
				client.close();
			}catch(Exception e1){}
		}
		return rtnbytes;
	}

}

⌨️ 快捷键说明

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