˹á
 úҹ
  C/C++ new
  Java new
 Sourcecode.TV
  Android
  Blackberry
  C/C++
  Java
  Linux
  Windows Phone
  ͧͧ
 
  .NET
  Android
  Blackberry
  C++Builder
  Delphi
  Java
  Mobile
  Open Source
  Pocket PC
  Visual Basic
  Web
  Windows Phone
  Others
 Ẻ¹
  ASP
  ASP.NET Webmatrix
  C++
  eVB
  J2ME
  Java
  PHP
 
  Android
  ASP
  C++
  VC++
  CGI-Perl
  Delphi
  Java
  jQuery
  PHP
  Visual Basic
  .NET
 ԡèҡ
  Դ...
  DoodeeHosting
  Ѻ͡Ẻ Ѳ䫵
  Freeware
  ѵҤɳ
  ª١
  ʶԵԼ
 Ŵ
 Ң
 дҹʹ
  .NET
  C/C++
  Delphi
  Java
  Palm/PocketPC
  Visual Basic
  Web
 
 дҹҹ
 ԧ
 ǡѺ
 ѵҤɳ
Social Network

Facebook  Twitter  YouTube
 New Article
 Webboard
 Freelanceboard
Freeware
 (BerDee)
(Android)
駩غ
駩غ(Android)
WebcamMonitor
WebcamMonitor(Windows)
scSendMail
scSendMail(Windows)
MSN Caption
MSN Caption(Windows)
  Freelance comment
  ԴͺʹФѺ...
2015-07-29 13:35:58
  Ҽͧ纷ѲҴ HTML5 ...
2015-01-18 15:33:54
  Ҽͧ纷ѲҴ HTML5 ...
2015-01-18 15:32:51
  ԴͺФѺ
ҹ...

2014-01-06 12:47:38
  ѧҤ͹ ͧ֡ͧ...
2013-07-06 01:04:37
  ʹ觢ͺࢵҤҤҡ͹ФѺ...
2013-03-24 18:54:20
  ѧդѺҹԴѺ 08...
2012-12-16 19:18:14
  ʹ㨤 Դ 0905076277...
2012-11-12 11:07:46
  Ѻ礹ѡ֡ͺѷ
...

2012-10-29 03:10:46
  sukit_te34@hotmail.com...
2012-10-29 03:09:36
  Webboard comment
  ͧ gotoxy ѧ...
2017-08-28 11:45:52
  ͧҧա u...
2017-08-27 20:09:01
  #define GLUT_DISABLE_ATEXIT...
2017-08-27 12:53:17
  դԻ͹ ...
2017-08-27 10:50:02
  Ѻ ͹ matlab ¹ matlab...
2017-06-03 16:27:23
  ੾зҧҴ ͧҢ...
2017-05-25 16:18:08
  ͧ˹Ѻ os ...
2017-05-25 16:12:47
  ¹ php curl ...
2017-04-20 01:04:20
  ¹ ...
2017-03-27 12:50:54
  ʧҷ ͧѾഷ...
2017-03-27 12:37:20
  Homework comment
  ͺسҡѺ...
2017-08-16 18:27:25
  ͧ ͧ ѧ ^^...
2017-04-18 18:40:46
  ͧ ͧ ѧ ^^...
2017-04-18 18:37:54
  á flowchart ѹ...
2017-04-18 17:43:33
  ҡ flowchart ...
2017-04-18 16:25:29
  kungking ӶäѺ ?...
2017-03-18 23:28:36
  ¹ʴͧ...
2017-03-06 10:56:25
  鴷ӧҹẺ ...
2016-09-06 01:00:12
  ҡҺ鴹Ѻѧ...
2016-09-05 09:31:27
  ͧ֡¹...
2016-04-22 00:47:49
  Article comment
  [b] , ...
2017-10-21 23:35:27
  [b] , ...
2017-10-20 10:05:06
  [b]5 ...
2017-10-18 08:19:17
  - ...
2017-10-18 07:17:11
  [b] ...
2017-10-18 06:07:31
  [b] 96 ...
2017-10-18 06:05:28
  - ...
2017-10-18 05:49:56
  code ͧ VB ú...
2017-09-28 16:50:02
  ҨѺ ͧ
...

2017-07-11 09:59:35
  ö͡Ѻ anycast ...
2017-07-05 10:12:35
  9Mcode comment
  ҡ...
2014-02-21 08:52:19

Link Exchange

ѵҤɳ
Statistics of Sourcecode in Thailand
 
 J2ME (Java Micro Edition) Tutorial  

- - - - - - - - - - - - - - ʹѺʹع- - - - - - - - - - - - - -

 J2ME (Java Micro Edition)
 
 

7 Network Connection

 

7 Network Connection

Generic Connection Framework

Generic Connection Framework (GCF) 繪شͧ API ١˹ CLDC ö¡ ҹҧ javax.microedition.io

ҡ شͧõԴ ͧ J2SE Ҩ java.io.* java.net.* Ѻҹ ػó բҴ (㹷 Ͷ) դͧҹ ˹¤ӷ 㹡õԴͼҹ TCP UDP (TCP õԴ ա׹ѹѺ С, UDP 繡õԴ ա׹ѹŷѺ)

Ҿ º Ẻ TCP ͹ѺѾ ա(觢) ҡռѺ зҺ ռѺ áзҺ Ẻ UDP º͹觨¸ ѺѺ ҧ Һ ҧҨ 件 ӵͺͧ ͷѺ UDP աõͺ׹ѹ 觵ç سͧ¹ٻẺ ͧѺ ѡͧ UDP Ѵǹ

Ѻ´ ͧ TCP UDP سö ҹҡ 䫵 www.sourcecode.in.th Ѻ

GCF classes & interfaces

ٻẺçҧͧҹ Class СõԴҹ ʴѧٻ

GCF Structure
ٻ 52 ʴ Class 㹡ҧõԴ

ҡٻ 㹡ҧ õԴ öз 4 ҧ¡ѹ

  • DatagramConnection, Ѻ Ẻ UDP
  • InputConnection, Ѻ
  • OutputConnection, 觢
  • StreamConnectionNotifier, õԴ

¡õԴͷ зӡõԴͼҹ StreamConnection(ӧҹѺ )

Connector Class

Connector Class ʷ㹡ҧõԴ ٻẺ㹡ҹ

  • public static Connection open(String name)
  • public static Connection open(String name, int mode)
  • public static Connection open(String name, int mode, boolean timeout)

´ͧ

  • name ͡ٻẺõԴͷẺ URI
  • mode ˹ѡɳСҹ READ, READ_WRITE, WRITE
  • timeout ˹ǧ 㹡ҧõԴ Թҡҷ˹ ҡԹҷ ӡ

ٻẺҧõԴẺ

  • DataInputStream openDataInputStream(String name)
  • InputStream openInputStream(String name)
  • DataOutputStream openDataOutputStream(String name)
  • OutputStream openOutputStream(String name)

ٻẺͧ URI <scheme>:<scheme-specific-part>
ҧ

  • HTTP Connection
    • Connector.open("http://jananet.com/");
  • Datagram Connection
    • Connector.open("datagram://www.jananet.com:7070");
  • Socket Connection
    • Connector.open("socket://127.0.0.1:5555");
  • Communication with a port
    • Connector.open("comm:0, ;baudrate=9600");
  • Open File
    • Connector.open("file://temp.txt");

سѧࡵ աͧ ͹ (" : ") 㹡ä ͺ֧͡Ţ (Ѻѧվ鹰ҹͧ Network öҹҡ 䫵 www.sourcecode.in.th )

աԴ ѺͧŢ, ͧͧŢ سö˹ͧ ͧ 仫ӡѺ Ţҵðҹ

  • 7 echo
  • 21 FTP
  • 25 SMTP
  • 80 HTTP (Hypertext Transfer Protocol)
  • 109 POP
  • 53 DNS (Domain Name Service)

Java Networking Model

㹡õԴ ҧͧ ͧͧ к ֧ͧͧԡ (ͧ Server) աͧ ͧ ԡ (ͧ Client) ѧٻ

Networking Model
ٻ 53 ʴ õԴҧ Client/Server

ҡٻͧ Server з˹ҷͤ ͧ ҡͧ Client ͧ Client ӡõԴ ͧ Server ѺõԴ͹

ѧҡ ͧͧöš¹ҧѹ ش ÷ӧҹ лԴ´¡ ѴõԴҧѹ

Ѻͧ ҤԺѵ աʴ 繶֧÷ӧҹͧ Client/Server Ѻ

HTTP Basic

õԴ͡ѹҧͧ Server ͧ Client 㹡úԡ ٻẺҵðҹ (Protocol) HTTP (Hypertext Transfer Protocol) ٻẺ ʴѧٻ

HTTP Process
ٻ 54 ʴ õԴҧ Client/Server ҹ HTTP

÷ӧҹ ӡ¡ Ѻ (Ҩ繢ͧ˹) Ƿӡû͹ 纷ͧ ,ѧǨзӡ ͢ Ш仢͢Ũҡͧԡ (Web Server) , ͧԡ зӡ觢 Ѻѧ ʴ

㹡õԴҧͧ Client Server ٻẺ Protocol ˹ѹ ҡ HTTP ٻẺŷҧѹ 繤觷ѡ

HTTP Request/Response

  • Request ͧ 觨ҡ Client ѧ Server
  • Respone õͺѺ ҡ Server ѧ Client

ԸաͧẺ Get Post

  • Ẻ Get 繡ͧ͢ŷ աʴŷṺ仴ա ¢ŴѧǨʴ բͨӡѴͧ§ 240 ѡ
  • Ẻ Post 繡ͧ͢ŷ աʴŷṺ仴ա ¢ŴѧǨʴ ö觢ҡ(֧дѺ MB)

Message Header

ǹǢͧͧ õͺʹͧ ١ҧͧ Server Ѻ Client

ǹͧͧ ͧ Client ա駢 Server Һ֧ѡɳТͧ ͧ Client öѺ仴 Server ӡ觢ŷ١ͧ ҧͧ HTTP Request

User-Agent: Profile/MIDP-1 Configuration/CLDC-1.0
Accept: text/xml
Connection: Keep-Alive

ҡٻẺ ͧ Message Header ҧ к֧͡ ͧ Client MIDP 1.0 CLDC 1.0 öѺ xml 觡õԴ͹ ж١ѡ աͧ ա ҾǴ Ѻ駷 session cookie

ǹͧõͺʹͧ ͧ Server ա駢 Client Һ֧Ţͧŷ Client ͧ ҧͧ HTTP Response

HTTP/1.1 200 OK
Date: Sunday 11-June-2002 04:14:12 GMT
Server JavaWebServer/1.1.1
MIME-Version: 1.0
Content-type: text/html
Content-length: 1029
Connection: Keep-Alive
Last-modified: Thursday 7-May-2000 12:15:35 GMT

MIDP Connectivity

㹡÷Ҩ MIDP ҧõԴ ҹҧ Socket öз ¼ҹҧҧ Connector ѧҧ

  • ҧõԴ
    • StreamConnection connection = (StreamConnection) Connector.open("socket://localhost:5050", Connector.READ_WRITE);
  • ԴõԴ
    • DataInputStream is = connection.openDataInputStream();
    • DataOutputStream os = connection.openDataOutputStream();

     

ѺõԴ͡Ѻ (HTTP) öзǡѹ ¼ҹҧ HttpConnection javax.microedition.io.HttpConnection ШʶҹС÷ӧҹ 3 ʶҹ

  • ҧ
  • Դ觢
  • ԴõԴ

㹡¹ѹҧʶҹʶҹ öзҹ ʹ

  • ¹ҡʶҹ ҧ ʶҹ Դ觢
    • openDataOutputStream(), openOutputStream(), openDataInputStream(), openInputStream(), getLength(), getType(), getHeaderField(), getEncoding(), getResponseCode(), getDate()
  • ¹ҡʶҹ ʶҹлѨغѹ õԴ觢
    • close(), getRequestMethod(), getURL(), getHost(), getFile(), getPort()

     

ҧ㹡ҧ õԴ բ鹵͹ѧ

  • ҧǵԴ
    • HttpConnection c = (HttpConnection) Connector.open("http://localhost:8080");
  • ˹ٻẺõԴ
    • c.setRequestMethod(HttpConnection.GET);
  • ˹سѵԢͧõԴ
    • c.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");

     

HTTP sessions & cookie

ҷӡõԴ͡Ѻ Web Server ͧ͢ õԴ ѹ鹨繡ҧ Session 鹺 Server 㹡红Ţͧҹ Шա觢Ţͧ Cookie ҡѺõͺʹͧ ѧҧͧ HTTP Response

HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 53
Date: Tue, 18 Dec 2001 17:19:22 GMT
Server Apache Tomcat/4.0.1 (HTTP/1.1 Connector)
Set-Cookie:JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;Path=/midp

ѧࡵա Ţͧ Cookie

㹡èд֧Ţͧ Cookie öʹ getHeaderField() ѧҧ

HttpConnection hc = (HttpConnection) Connector.open(url);
String cookie = hc.getHeaderField("Set-Cookie");
if(cookie != null) {
   int semicolon = cookie.indexOf(';');
    mSession = cookie.subString(0, semicolon);
}

ͤسͧè cookie 仡Ѻͧ ա öҹ ʹ setRequestProperty() ѧʴ ҧ

HttpConnection hc = (HttpConnection) Connector.open(url);
if(mSession != null) hc.setRequestProperty("Cookie", mSession);

 

㹺 ǡѺ ѡɳТͧ õԴ ҧ Client/Server ջª ѹҡ 㹡Ѳ Դҡ觢 سͧҤԺѵ 繶֧ҹԧ

 

BACK

µͨ Ѻͧ macbook pro 2016 (usb-c to HDMI)
µͨ Ѻͧ macbook pro 2016 (usb-c to HDMI) ´дѺ 4K
ŧ Mini DisplayPort to HDMI Adapter ŧ Mini DisplayPort to HDMI Adapter Ѻͧ macbook air/pro, mac mini
ŧ Mini DisplayPort to HDMI Adapter Ѻͧ macbook air/pro, mac mini
µٿѧ Ъ Ѻ iPhone 7  7 Plus
µٿѧ Ъ Ѻ iPhone 7 7 Plus
ŧҡ USB-C Type  USB 3.1 Ѻ MacBook
ŧҡ USB-C Type USB 3.1 Ѻ MacBook
䢤ǧѺͧ Macbook Air/Pro
䢤ǧ Ѻͧ Macbook Air/Pro (300ҷ)
HDMI  3 ͡  1
HDMI 3 ͡ 1 (350ҷ)
Ի͹¹
¹¹ͷ
¹¹͹´
¹¹
¹¹ վʾ
¹¹
¹ҹԹء
¹¹Թ⿹
¹¹Ϊ ʤ
9M Blog ͧ͡ ¹ͧ
ԡ ҾѺԭ
OrmSin.com: ˹ѧͧҹ--չ (country crafts)
ѵҤɳ
 
Tutorial
eVB Tutorial
ASP.NET Webmatrix Tutorial
J2ME Tutorial
C++  Tutorial
Java  Tutorial
PHP Tutorial
ASP Tutorial
 
ẺǨ
Freelance ѺѲ

Home - Article - Tutorial - Sourcecode - Dev Handbook - Search - WebBoard - Links - About Us

ʧǹԢԷ Ѵ͡ ӫ Ѵŧ ٻẺ Ѻ͹حҵѡɳѡ
Ţ¹ҳԪ硷͹ԡҡзǧҳԪ: 7100503002000
Copyright 2001 SourceCode.in.th