当前位置导航:炫浪网>>网络学院>>编程开发>>JAVA教程>>Java进阶

一个tcp/ip套节字编程的javabean


  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);
  }
  
  }
相关内容
赞助商链接