To Previous Chapter To Table of Contents To Bottom of Page

Chapter 14 - The Socket Programming Interface

  1. Development of the Socket Programming Interface
    1. TCP/IP API is portable (across OS and hardware platforms) and language-independent (C, Java)
    2. API - interface between an application program and the communication protocol in an operating system
    3. follows the UNIX I/O System [open-read-write-close system] using pielines
    4. TCP/IP uses a socket number to uniquely identify the connection

  2. Socket Services
    • 3 types of socket interfaces
      • TCP stream communications
      • UDP datagram communications
      • raw datagram
    • six basic communications commands
      • open - establish a socket
      • send - send data to a socket
      • receive - receives data from a socket
      • status - obtains status info about a socket
      • close - terminates a connection
      • abort - cancels an operation and terminates the connection

    • Transmission Control Block (TCB) - data structures that contains details about a connection
    • Creating a Socket function call - socket(family, type, protocol)
      • family - TCP/IP (AF_INET), AppletTalk (AF_APPLETALK), UNIX (AF_UNIX)
      • type - SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
      • protocol
    • Binding a Socket function call - bind(socket, local_address, address_length)
    • Connecting to the Destination - connect(socket, destination_address, address_length)
    • The open Command
      Type InputOutput
      Unspecified passive open local port
      optional: timeout, precedence, security, maximum segment length
      Local connection name
      Fully specified passive open local port, remote IP address, remote port
      Optional: timeout, precedence, security, maximum segment length
      Local connection name
      Active open local port, destination IP address, destination port
      Optional: timeout, precedence, security, maximum segment length
      Local connection name
    • Sending Data
      • send( socket, buffer_address, length, flags)
      • sendto( socket, buffer_address, length, flags, destination, address_length)
      • sendmsg(socket, message_structure, flags)
      • write(socket, buffer_address, length)
      • writev(socket, iovector, length)
    • Receiving Data
      • read( socket, buffer, length)
      • readv(socket, iovector, length)
      • recv( socket, buffer_address, length, flags)
      • recvmsg(socket, message_structure, flags)
      • recvfrom(socket, buffer_address, length, flags, source_address, address_length)
    • Server Listening
      • listen(socket, queue_length)
      • accept(socket, address, length)
    • Getting Status Information [read from the TCB]
      1. getsockopt(socket, level, option_id, option_result, length)
      2. getpeername(socket, destination_address, address_length)
      3. getsockname(socket, local_address, address_length)
      4. sethostname(name, length)
      5. gethostname(name, length)
      6. setdomainname(name, length)
      7. getdomainname(name, length)
    • Closing a Connection - close(socket)
    • Aborting a Connection - close()
    • UNIX Forks / threads
      • fork creates a copy of the existing application as a new process and starts executing it
      • exec
      • Each new thread that is created inherits a copy of all open sockets from the thread that created it.


Network Programming in Java


To Previous Chapter To Table of Contents To top of page