码迷,mamicode.com
首页 > 其他好文 > 详细

tcp/ip 传输

时间:2015-01-15 00:22:44      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

 

 // socket读取流
 protected BufferedReader cin = null; // socket读取流
 // socket发送流
 protected PrintWriter cout;

/***************************************************************************   * 发送信息到 建设银行   **************************************************************************/

 public static String sendMsgJSYH(String msg, String sydwId)    throws FESException {

  String message = "";  

 // 获取服务IP   String serviceIp= "";

  // 获取服务端口   int port=0;

  try {    

// 获取服务IP    serviceIp =  FESUrlConfig.getFESConfig().getItCCBIp();

//   serviceIp="172.16.17.24";    

// 获取服务端口    port =  FESUrlConfig.getFESConfig().getItCCBPort();

//   port=8000;  

  SocketClients sc = new SocketClients(serviceIp, port);   

 log.error("建设银行服务(IP:" + serviceIp + " 端口:" + port );  

  message = sc.sendXmlMsgToJSYHLS(msg.getBytes());   

} catch (ConnectException e) {

   log.error("建设银行服务(IP:" + serviceIp + " 端口:" + port + ")连接失败!"      + e.getMessage());

   throw new FESException(e);   

} catch (SocketTimeoutException e) {

    log.error("建设银行服务(IP:" + serviceIp + " 端口:" + port + ")响应超时!"      + e.getMessage());  

   throw new FESException(e);   

} catch (Exception e) {  

  log.error(e.getMessage(), e);   

}  

 return message;  }  

 

 

方法2:

public String sendXmlMsgToJSYHLS(byte[] sendMsg) throws Exception {   

  // 建立连接   this.startConnect();

  logger.info("\nSend message:\n"+ new String(sendMsg));  

 // 发送消息   this.sendBuffer(sendMsg);

  // 接收消息   byte[] responseMsg = this.recieveBufferYH();  

 // 关闭连接   this.shutdownConnection();  

 String msgRes =new String(responseMsg);

  return msgRes;

 }

 

/**
  * @description 发送信息
  * @author fei_yfan
  * @param bufferString
  *            发送消息内容
  * @throws IOException
  */
 public void sendBuffer(byte[] bufferString) throws IOException {
  cout.write(new String(bufferString));
  cout.flush();
 }

 

 

public byte[] recieveBufferYH() throws Exception {
  StringBuffer  sb = new StringBuffer();
  String s ="";
  //从文件中按字节读取内容,到文件尾部时read方法将返回-1
  while((s=cin.readLine())!= null){
   sb.append(s+"\n");
  }
  return sb.toString().getBytes();
 }

 

tcp/ip 传输

标签:

原文地址:http://www.cnblogs.com/li-xy/p/4225095.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!