WEB开发网
开发学院WEB开发Jsp 一个tcp/ip套节字编程的javabean 阅读

一个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);
  }
  
  }

Tags:一个 tcp ip

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接