network programming - What is a socket, physically? -
i prefer pyhsical meaning of programming concept logical meaning. here comes question.
as review socket programming paradigm, noticed bind(), connect() functions tuning socket created socket() function. guess socket() function creating data structure (and possibly data structure in kernel space) hold the details end-to-end communication settings between client , server. , bind(), connect() fill in data structure.
i not familiar implementation of socket api, hope address concern.
this highly platform-dependent. point of api don't need know these details.
if you're interested in learning (which shouldn't applications , system applications programming), can download linux kernel source archive kernel.org , examine linux's tcp/ip implementation looking under net/ipv4
to add clarity,
to transport data across network, adhere standards defined international standards organization. have standard called osi, or open systems interconnection, model.
this model defines 7 layers of abstraction applications move data across network. i'll talk first 4, the pertinent ones question.
physical layer:
this layer defines how data transmitted on media. hardware vendors adhere defined standards on how move data. standards agree on electrical signals , electronic aspects of data moving.
how fits system:
hopefully, there's little software support required layer. whatever programming done here done on-module , not in kernel or application.
data link layer:
this first layer arguably involves sort of programming. layer defines line-level protocols operate on physical links. ethernet 1 protocol. frame relay another. token ring another. each end of link must running same data link protocol. layer combines compatible physical layer standard give means transfer data 1 host another. in many regards can thought more of appendix physical layer rather own layer, because link-level protocols defined here that's not great analogy. layer gives physical addresses nodes on network.
how fits system:
you'd need write driver talk interface module runs these data-link protocols. depending on module , system, module may have needs work, or may need system-level help. ideally, create set of code interfaces (perhaps implemented structs contain function pointers appropriate handling of i/o.. don't know) , when install new physical module, driver need implement code interfaces , physical module usable.
network layer
this layer provides ability move data between networks (in case of tcp/ip). internet protocol defined @ layer. layer gives logical addresses nodes can grouped networks. knowing network (also called subnet, determined programatically using subnet mask) host on, run algorithms correctly move data 1 network another. if 1 host on network in china , 1 host on network b in australia, algorithms @ level in charge of providing path links these networks , therefore these hosts.
an important thing programming layer should able "plug in" data link layer transmit over. means once create code on system transmit on ethernet, token ring, 3g, or frame relay should able use of them without network layer needing know data link technology using. logic of moving data between networks should not depend on actual physical link operating on.
this layer puts data packets, , packets routed on internet.
how fits system:
all of layer must coded part of system. entirely software construct , should isolated as possible data link layer. not enough of expert in practice how accomplished. because functionality of layer system-defined, have total control on software must support. makes construction of code interfaces allow using layer higher-layer protocols rather simple compared ones in data link layer.
transport layer:
this layer defines segmentation of data (because if sent giant pieces of data @ once, hardly make in order). layer defines tcp, provides hand-shaking, checksums, packet ordering, variable data window sizes, , guaranteed reliabilty. tcp gives ability create multiple logical channels of communication on same physical link. differentiates 1 coversation on link conversation on same link. udp defined @ level, , can thought of extremely light-weight tcp. udp provided none of beneifts of tcp still provides physical channel multiplexing.
if transport layer written well, applications don't need (speaking code architecture standpoint) worry whether transport layer using tcp or udp (just mentioning these 2 b/c yare popular on ip). while may pick 1 or other based on timing performance needs or reliability needs (and in practice, applications make assumption 1 running), application doesn't need have exact knowledge of 1 running.
because layer built on top of network layer, don't need worry how our data 1 host if on different networks. if router running standard routing protocol, augmented statically-defined routes, don't need worry that. it's taken care of network layer. if network-layer configuration changes on host running, doesn't matter. don't need change our entire application account this.
how fits system:
very similar network layer, except provides different functionality network layer. additionally, these interfaces used more in user-space network layer interfaces. layer defines sockets use in tcp/ip networking.
hope helps , can understand why question little confusing of us.
Nice Blog Post thanks for sharing it.
ReplyDeleteTp link service provider
TP-Link Support Australia