#ff0000 13  2006 . - #000655     J2ME - Generic Connection Framework (GCF) API. , , HTTP 

#def      ,  J2ME     .        .   J2ME         J2SE.      J2ME   MIDP API: Generic Connection Framework (GCF).  GCF    .       javax.microedition.io. 

 GCF   Connector   .  Connector     .     . 
  ,   HTML . 
HttpConnection MyCon = (HttpConnection)
Connector.open("http://www.mobilab.ru", Connector.READ_WRITE, true);
 Connector ,     ,    URL .     "http://www.mobilab.ru". URL     : ,   .       .     . 
{}: [{}] [{}] 
   URL    "http"   "www.mobilab.ru".  . GCF    HTTP.     : HTTP	http://www.host.com: 8080 
Socket 	socket://host.com:80 
Socket Listener	socket://:1234 
Datagram Sender	datagram://host.com:9001 
Datagram Listener	datagram://: 9001 
File 	file:/myfile.txt 
Comm Port 	comm:com0;baudrate=19200;parity=odd 

   Java ,        .     TCP ,      .      User Datagram Protocol (UDP), ,            , GCF   . 
         .     "",        .     ,      .     ,       .     ,    ,       ,     .        . 
             IP . 
try     {
  DatagramConnection dgc = (DatagramConnection)
    Connector.open("datagram://localhost:9001");
  try {
    byte[] payload = "Test Message".getBytes();
    Datagram datagram = 
      dgc.newDatagram(payload, payload.length);
    dgc.send(datagram);
  } finally {
      dgc.close();
  }
} catch (IOException x) {
  x.printStackTrace();
}

      "Test Message",     9001   (    ). 
    ,       ,   9001,        ,      . 
   ,   : 
try {
  DatagramConnection dgc = (DatagramConnection) 
    Connector.open("datagram://:9001");
  try {
    int size = 100;
    Datagram datagram = dgc.newDatagram(size);
    dgc.receive(datagram);
    System.out.println(
      new String(datagram.getData()).trim());
  } finally {
      dgc.close();
  }
} catch (IOException x){
  x.printStackTrace();
}

       9001. ,       100 .       .     ,   receive(),         ,     .           . 

     TCP -.          .  ,             .     .      ,      .         ,     . 
   ,    . 
try
{
  ServerSocketConnection ssc = (ServerSocketConnection) 
  Connector.open("socket://:9002");
  StreamConnection sc = null;
  InputStream is = null;
  try{
    sc = ssc.acceptAndOpen();
    is = sc.openInputStream();
    int ch = 0;
    StringBuffer sb = new StringBuffer();
    while ((ch = is.read()) != -1){
      sb.append((char)ch);
    }
    System.out.println(sb.toString());
  } finally{
      ssc.close();
      sc.close();
      is.close();
  }
} catch (IOException x) {
    x.printStackTrace();
}

   ServerSocketConnection   9002.        -    .    acceptAndOpen()     .     ,      SocketConnection.         . 
  ,     . 
try{
  SocketConnection sc = (SocketConnection) 
    Connector.open("socket://localhost:9002");
  OutputStream os = null;
  try{
    os = sc.openOutputStream();
    byte[] data = "Hello from a socket!".getBytes();
    os.write(data);
  } finally{
      sc.close();
      os.close();
  }
} catch (IOException x){
     x.printStackTrace();
}

SocketConnection    9002   .    , OutputStream     .  ,       .           ,   . 
 Web 
        MIDP HttpConnection.    ,   HttpConnection    MIDP,   CLDC. HttpConnection    InputStream  OutputStream.  HttpConnection       InputStream   OutputStream.       . OutputStream    InputStream (     InputStream).      ,     ,   ,  .    HTTP  -. 
HttpConnection     . HTTP        . 
 
 
 
    HttpConnection    "".       ,    (GET/POST)   HEAD  (   setRequestMethod()  setRequestProperty()). 
  ""        ,       : 
openInputStream 
openDataInputStream 
getLength 
getType 
getEncoding 
getHeaderField 
getResponseCode 
getResponseMessage 
getHeaderFieldInt 
getHeaderFieldDate 
getExpiration 
getDate 
getLastModified 
getHeaderField 
getHeaderFieldKey 
       ""   setRequestMethod()  setRequestProperty()    IOException. 
       HttpConnection.    ,    80 .       GET. 
HttpConnection c = null;
InputStream is = null;
StringBuffer sb = new StringBuffer();
try {
  c = (HttpConnection)Connector.open(
     "http://www.mobilab.ru", 
     Connector.READ_WRITE, true);
  c.setRequestMethod(HttpConnection.GET); //default
  is = c.openInputStream(); // transition to connected!
  int ch = 0;
  for(int ccnt=0; ccnt < 150; ccnt++) { // get the title.
    ch = is.read();
    if (ch == -1){
      break;
    }
    sb.append((char)ch);
  }
}
catch (IOException x){
     x.printStackTrace();
}
finally{
     try {
       is.close();
          c.close();
     } catch (IOException x){
          x.printStackTrace();
     }
}
System.out.println(sb.toString());

       www.mobilab.ru.   HttpConnection     ,      80.     GET (-  GET  -         . 
   ?
  , GCF      .    ,         .  MIDP 1.0     HTTP,         .    ,  ,     . 
  HTTP    ,       ,  ,     80    .      .  ,     ,      ,  . 
           .  ,                        . 
  -    HTTP .           ,         HTTP.  ,      ,       . 
GCF              J2ME . GCF              .       GCF                GPS .         ,    .