菜鸟请大虾帮忙看一下这段代码的问题,关于Socket的
这是一个提供网络连接服务的类:
import java.io.*;
import java.net.*;
public class CallLink
{
//使用套接字进行连接
String ipAddr;
Socket outSock=null;
ServerSocket inServSock=null;
Socket inSock=null;
int TALK_PORT=12630;
public CallLink(String inIP)
{
ipAddr=inIP;
}
void open() throws
IOException,
UnknownHostException {//打开网路连接
if(ipAddr!=null)
outSock=new Socket(ipAddr,TALK_PORT);
}
void listen() throws IOException
{//监听,等候呼叫
inServSock=new ServerSocket(TALK_PORT);
inSock=inServSock.accept();
System.out.println( "get connection OK. ");
}
public InputStream getInputStream()throws IOException
{//返回音频数据输入流
if(inSock!=null)
return inSock.getInputStream();
else { System.out.println( "cannot get input stream. ");
return null;}
}
public OutputStream getOutputStream()throws IOException
{//返回音频数据输出流
if(outSock!=null)
return outSock.getOutputStream();
else { System.out.println( "cannot get output stream. ");
return null; }
}
void close() throws IOException
{//关闭网络连接
inSock.close();
outSock.close();
}
}
问题:
curCallLink=new CallLink(conIP);
try {
curCallLink.open();
if(curCallLink.outSock!=null)
{curCallLink.inSock=curCallLink.outSock;}