📄 d_communication.java
字号:
/*
* Created on 2004-10-27
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package cn.edu.hust.cgcl.biogrid.dispatcher;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.Socket;
//communicate to other dispatcher node
public class D_Communication {
private static final int TIME_OUT = 1000;
private Socket nodeSocket;
private String ipAddr; //target dispatcher node's ipaddr and port
private int dispatcherPort;
protected Item D_item;
protected ObjectInputStream iob;
protected ObjectOutputStream oob;
protected PrintWriter os;
protected BufferedReader is;
public D_Communication(String _ipAddr, int _Port) {
this.ipAddr = _ipAddr;
this.dispatcherPort = _Port;
nodeSocket=null;
os=null;
is=null;
//tmpDispatcherInfo=new DispatcherInfo();
}
protected D_Communication(){}
public boolean onpoll() {
if (nodeSocket == null) {
if (!initCommunication()) {
return false;
}
}
if (process()) return true;
return false;
}
protected boolean process()
{
return true;
}
private boolean initCommunication() {
try {
this.nodeSocket = new Socket(ipAddr, dispatcherPort);
nodeSocket.setSoTimeout(TIME_OUT);
is = new BufferedReader(new InputStreamReader(nodeSocket.getInputStream()));
os = new PrintWriter(nodeSocket.getOutputStream());
oob=new ObjectOutputStream(nodeSocket.getOutputStream());
iob=new ObjectInputStream(nodeSocket.getInputStream());
}
catch (Exception e) {
if (nodeSocket!=null)
{try{nodeSocket.close();}
catch(IOException e1) {e1.printStackTrace();} }
if(os!=null) os.close();
if(is!=null)
{try{is.close();}
catch(IOException e1) {e1.printStackTrace();} }
if(iob!=null)
{try{iob.close();}
catch(IOException e1) {e1.printStackTrace();} }
if(oob!=null)
{try{oob.close();}
catch(IOException e1) {e1.printStackTrace();} }
return false;
}
return true;
} //initDispatcher
public void log(Exception e)
{
e.printStackTrace();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -