Assalamulaikum wbt..
Alhamdulillah, first syukur kpd Allah S.W.T krn kite msih lgi dianugerahi nikmat Iman dan Islam wlaupun hkikatnye kite selalu asyik dan lalai dlm menjalankan tggjwab as a khalifah-Nya.
"INTRODUCTION"
Entry y lepas aku da explain sikit sal ape die socket programming..Kalu korang xbace lgi, sila la bace since aku tkut da y termuntah lak nnti..1st, keep in mind that socket is like a tunnel so that my next explaination would be easy for you guys..Kat bwh nie ade screenshot process flow on how socket programming really works. Oleh kerana buku Unix Network Programming API aku kat en. Azri, mka gambo kat bwh nie adalah gambo y aku google je.
"BRIEFLY"
Socket programming melibatkan communication between server n client. Who's gonna be server n client ?? Jwpan nye adlah terletak pd kite as a programmer. Pd aku, to make it simple, Server is the one who provide the service n client is the one who request/consume the service..For instance, Facebook y hri2 korang usya tue kn. Facebook mainframe wil be the server, n your machine will be the client n request sumer msg2 kat wall..
"1ST, SERVER INITIALIZATION"
Bende y plig penting adalah server perlu ade ip address n port..Bygkn korang da rumah with one address but more doors. Korang kne la decide which "door" y korang nk gune. Port 1-1024 is reserved by IANA as a default web service cam port 80 utk HTTP, port 22 utk FTP and so on..Suggestion aku gune port 2000 and above..1st, initialize Socket class or "tunnel" n call library2 y berkaitan..Next, bind kn dgn ip address machine korang n port y korang nk gune. Xksah IPv4 or IPv6, the step is still same but the address representation n network masking is little bit different. Once korang dh bind, korang sebenarnye dh advertise through out all computer in local network y korang ade "tunnel" ke laptop korang..Be carefull since this is the actuall way on how hackers gain access on victim's computer.So aku advise try dlu dlm mode local host n your ip address should be "127.0.0.1" or "::1" for IPv6..Lepas "tunnel" dh establish, server will be in "daemon state" - a program that always running in the background n listen for any incoming request.
"CONNECTION ESTABLISHMENT"
Next, prepare your client program. Client xperlu bind ip address n port ke socket. What he need to know is with who he want to connect. Atas sbb itu, korang kene supply kat die ip address n port server y korang dh wat td..Yela, kalu x, cmana lgi die nk connect ke server..Then bile connect ke server, 1 "path" akn di establish between your client n server. Utk permulaan, xpyahla pk soal connection secure or x secure, in fact, mmg xsecure pn..Kalu nk wat style "ssl" connection with further packet encryption, sila wat ms kat phase ni.
"DATA TRANSMISION"
Once dh connect, client n server should bleh communicate n pass some string msg as a sample data. Skg nie, data trasmision depend on what type of network protocol y korang nk gune, TCP or UDP. TCP is little bit complex compared with UDP but more reliable..Kenapa?? ok aku explain.
In TCP, stp data akn di convert from host byte to network byte, tmbah dgn other TCP header like source n destination info, TTL (time to live), checksum, padding, "window" size, packet sequence n etc. Maximum transmision unit (MTU) pn agak besar but fixed. Which means kalu buffer size = 1024 byte, but korang juz nk send hruf "A" je, TCP protocol akn automatik add some padding utk mksure die reach MTU size. One more, mose of the time kite akn download muvie y bersize besar >500 MB rite. Its imposible to transmit whole file with single data packet. In reality (like what all download manager do), this 500 MB file akn dipisah2kan kpd packet2 y lebih kecik mengikut size MTU td n also "window" size..Ape die "window" size nie?? Next post insyaAllah aku akn explain sikit since ia melibatkn 3-way handshake n bla bla bla..So, packet2 kecik nie td aku lbih suke pgil as a "chunk"..Each chunk akn di bg "no giliran" or sequence number. Then all chunk will be sent regardless which one is the first or last. Bile packet2 or chunk nie arrive kat laptop korang (client), download manager akn combine or rebuild blik to form the big file again.
In UDP is totally different, each file still need to be splitted into chunks but there is no 3-way handshake, cheksum, n byk lagi. In TCP kite pgil packet, but in UDP kite pgil datagram. Since there no overload network header information, UDP datagram mmg ringan n kcik. Ditambah plak dgn xder sistem "handshake" or acknowledgment, datagram besenye mmg cepat n lagi pantas drpd send gune TCP protocol. But once again, there is no guarantee y datagram nie td akn smpai kpd client. Aku bg contoh, let say la file y besar td split kpd >1000 chunk datagrams, blum tentu datagram ke-5 akan smpai dlu dripad datagram ke-10..Thats why UDP xseswai utk send file bersize bsar, tp advantage die amat berkesan bile nk wat application y byk gune message passing (instant messanger, distributed system).
"CLOSE CONNECTION"
After data transmision hbis, client akn close connection dlu, then bru server..After that, server akn return blik kpd "listen" mode coz cm aku ckp td, server ack like a "daemon" - always running. Bile connection dh close, next client bleh establish connection bru dgn server..
CONCLUSION
Kalu nk further lgi, korang bleh wat Socket connection either in asynchronous or syncronouse mode, non-blocking or blocking state n byk lgi. Aku tw rmai y xminat nk tw bnde2 complicated cmni, but the thing is, its good to expand your knowledge n make yourself "knowledgable" person instead of doing assignment n let that particular knowledge juz "pass by" your subconscious mind..Gain the concept, n apply it whenever needed..
Gudluck..
.
27 February 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
terima kasih.