Re: socket()
From: Roger Abell (mvpNOSpam_at_asu.edu)
Date: 02/27/05
- Previous message: Roger Abell: "Re: Deny _WRITE_ access to a file"
- In reply to: visu: "socket()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sun, 27 Feb 2005 09:08:15 -0700
That is an interesting observation Shanker.
I believe the answer is partly one of history, and partly
one of understanding the deeper structures involved.
I am pretty rusty on this stuff, but will take a run at giving
you at least one point of view.
Use of the two step creation of the socket and then of
binding it to begin listening goes back to the beginning
of Tcp/Ip network use in Unix. The socket call causes
the construction of the needed support in the network
stack, basically in effect saying here is something that
can/will handle/get-handed network packets, whereas
binding activates the listener on a specific port.
Think of the overheads here and of where what is being
done. Socket call fills a struct in the stack and provides
the call info the stack will need in order to pass a packet.
Binding just makes this active by saying what packets.
On the other hand, opening a file is a matter of getting
a handle to the file, in the older days grabbing an inode,
and then using this with access methods that already are
available as a part of the OS install. By comparison,
with the network socket created by your listener you
have effectively defined the "assess method", and the
port call ties it into the stack somewhat like giving the
file handle to the file handler.
Could you encapsulate the network setup of your service
so it can be done is a single call? Sure. This is often
the case. Should the OS make this the only way? No.
That would remove capability, like inactivating a listener
without removing it, like rebinding to different port, etc.
Should OS provide two step way to open file? It does
if you want to go to lower level, for example if you write
something that needs raw access. Should the OS have
made it necessary to use the lower, unencapsulated way?
No, not for a common access pattern.
-- Roger Abell Microsoft MVP (Windows Security) MCSE (W2k3,W2k,Nt4) MCDBA "visu" <shanker_bejjanki@persistent.co.in> wrote in message news:eg4nldKHFHA.2156@TK2MSFTNGP09.phx.gbl... > Hi > > > > When we create socket for server , first we use SOCKET () then we will Bind > () to the port . > > what is the use of this kind of mechanism . > > > > If u compare this with file opening . why not fopen() used then it will > Bind() with file name ..? > > we use only one statement to open file , But why we use two statement to > open socket connection.. > > (why can't we provide port , server structure in socket.) . > > > > why they designed like that ...? > > > > Please clear me.. > > > > Thanks > > Shanker Bejjanki > >
- Previous message: Roger Abell: "Re: Deny _WRITE_ access to a file"
- In reply to: visu: "socket()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|