示例#1
0
  /** Constructor declaration */
  public JICPConnection(TransportAddress ta, int timeout) throws IOException {
    // #MIDP_EXCLUDE_BEGIN
    // For some reason the local address or port may be in use
    while (true) {
      try {
        // #PJAVA_EXCLUDE_BEGIN
        sc = new Socket();
        bindSocket(sc);
        sc.setTcpNoDelay(true);
        sc.connect(new InetSocketAddress(ta.getHost(), Integer.parseInt(ta.getPort())), timeout);
        // #PJAVA_EXCLUDE_END
        /*#PJAVA_INCLUDE_BEGIN
        sc = new Socket(ta.getHost(), Integer.parseInt(ta.getPort()));
        #PJAVA_INCLUDE_END*/
        is = sc.getInputStream();
        os = getOutputStream();
        break;
      } catch (BindException be) {
        // Do nothing and try again
      }
    }
    // #MIDP_EXCLUDE_END

    /*#MIDP_INCLUDE_BEGIN
    String url = "socket://"+ta.getHost()+":"+ta.getPort();
    sc = (StreamConnection) Connector.open(url, Connector.READ_WRITE, false);
    is = sc.openInputStream();
    os = getOutputStream();
    #MIDP_INCLUDE_END*/
  }
示例#2
0
 public JICPPacket readPacket() throws IOException {
   if (sc != null) {
     if (is == null) {
       // #MIDP_EXCLUDE_BEGIN
       is = sc.getInputStream();
       // #MIDP_EXCLUDE_END
       /*#MIDP_INCLUDE_BEGIN
       is = sc.openInputStream();
       #MIDP_INCLUDE_END*/
     }
     return JICPPacket.readFrom(is);
   } else {
     throw new IOException("Connection closed");
   }
 }