一个tcp/ip套节字编程的javabean
2008-01-05 19:26:20 来源:WEB开发网核心提示:package card_s; import java.net.Socket; import java.io.*; public class card_s { Socket client; BufferedReader socketReader; String line = null; PRintWriter sock
package card_s;
import java.net.Socket;
import java.io.*;
public class card_s
{
Socket client;
BufferedReader socketReader;
String line = null;
PRintWriter socketWriter;
public String card_status(String userno)
{ try
{
//创建一个socket
client = new Socket("192.168.0.13",2002);
//创建输入输出数据流
socketReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
socketWriter = new PrintWriter(client.getOutputStream());
//发送数据
socketWriter.println(userno);
socketWriter.flush();
//设置联接超时的时间
client.setSoTimeout(20000);
//接收数据
line=socketReader.readLine();
//关数据流
socketWriter.close();
socketReader.close();
client.close();
}
catch(Exception e)
{
line="系统忙,请稍后再试";
}
return(line);
}
}
更多精彩
赞助商链接