📄 datalink.java
字号:
/*
* DataLink.java
*
* Created on 2006年12月10日, 下午2:12
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package cn.edu.tsinghua.thss.talkie.connect;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
* @author promenade
*/
public class DataLink {
/** Creates a new instance of DataLink */
String ipAddr = null;
Socket outSock = null;
ServerSocket inServSock = null;
Socket inSock = null;
int DATA_PORT = 5002;
public DataLink(String inIP) {
ipAddr = inIP;
}
public boolean open() throws IOException, UnknownHostException {
if (ipAddr != null){
outSock = new Socket(ipAddr,DATA_PORT);
}
return outSock.isConnected();
}
void listen() throws IOException {
inServSock = new ServerSocket(DATA_PORT);
inSock = inServSock.accept();
}
public InputStream getInputStream()throws IOException {
if (inSock != null)
return inSock.getInputStream();
else
return null;
}
public OutputStream getOutputStream() throws IOException {
if (outSock != null)
return outSock.getOutputStream();
else
return null;
}
void close() throws IOException {
inSock.close();
outSock.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -