Esempio n. 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*/
  }
Esempio n. 2
0
 public void close() throws IOException {
   IOException firstExc = null;
   if (is != null) {
     try {
       is.close();
     } catch (IOException e) {
       firstExc = e;
     }
     is = null;
   }
   if (os != null) {
     try {
       os.close();
     } catch (IOException e) {
       firstExc = (firstExc != null ? firstExc : e);
     }
     os = null;
   }
   if (sc != null) {
     try {
       sc.close();
     } catch (IOException e) {
       firstExc = (firstExc != null ? firstExc : e);
     }
     sc = null;
   }
   if (firstExc != null) {
     throw firstExc;
   }
 }
Esempio n. 3
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");
   }
 }
Esempio n. 4
0
 // #MIDP_EXCLUDE_BEGIN
 public void setReadTimeout(int timeout) throws IOException {
   if (sc != null) {
     sc.setSoTimeout(timeout);
   }
 }
Esempio n. 5
0
 public int getLocalPort() {
   return sc.getLocalPort();
 }
Esempio n. 6
0
 public String getLocalHost() {
   return sc.getLocalAddress().getHostAddress();
 }
Esempio n. 7
0
 public String getRemoteHost() throws Exception {
   return sc.getInetAddress().getHostAddress();
 }