Re: socket()

From: Roger Abell (mvpNOSpam_at_asu.edu)
Date: 02/27/05

  • Next message: Brent: "Block saving of certain file types in share"
    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
    >
    >
    

  • Next message: Brent: "Block saving of certain file types in share"

    Relevant Pages

    • Re: Sending data to local port
      ... "Port" is a concept applies to TCP/UDP, so, if you want to send something to ... way to the bottom of the stack.). ... and network layers of the stack. ... gradually makes its way back up through the network layers. ...
      (microsoft.public.win32.programmer.networks)
    • RE: [ofa-general] Re: [PATCH RFC] RDMA/CMA: Allocate PS_TCPportsfrom the host TCP port space.
      ... PS_TCPportsfrom the host TCP port space. ... And actually RDMA stack exist and no one said it should be thrown away ... detail how RDMA (a network technology) is treated as bastard child by ...
      (Linux-Kernel)
    • Re: IPC Howto -- client and server; name registration, how?
      ... > socket example code to see if it does what you want. ... and network distributed clients). ... "locally" defined port number, ... that server is on today? ...
      (comp.unix.bsd.freebsd.misc)
    • Re: max buffer for send?
      ... > queue system. ... you are asking the socket stack _only_ to queue the ... >> can accept that and move on, you will be a better network developer. ...
      (microsoft.public.win32.programmer.networks)
    • Re: Simulate socket with files or stdin/stdout
      ... > over a TCP/IP network. ... > One idea is to use stdout and stdin (but I'm not even sure if stdout/in are ... then it will almost for sure talk directly to the socket. ... application host, port 2004, and interact with the application. ...
      (comp.lang.python)