Sockets - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Sockets

Description:

Sockets were introduced in 1981 as a generic interface that would ... catch(IOException e) { System.err.println(e); 16. Version Oct99 j. c.westlake_at_staffs.ac.uk ... – PowerPoint PPT presentation

Number of Views:279
Avg rating:3.0/5.0
Slides: 26
Provided by: Staffordsh75
Category:

less

Transcript and Presenter's Notes

Title: Sockets


1
Sockets
  • What are Sockets?
  • Why are Sockets used?
  • What do Sockets do?
  • How to use Sockets

2
What are sockets?
  • History
  • Sockets were introduced in 1981 as a generic
    interface that would provide Unix to Unix
    communications over networks
  • Nowadays Sockets are supported on nearly every
    operating system e.g. WindowsJavaOS
  • Microsoft Windows socket is known as WinSock
  • Sockets are important to know about as they
    currently (1999) are the standard for network
    application providers on TCP/IP networks

3
What are sockets?
  • Sockets is a method for communication between a
    client program and a server program in a network.
  • Sockets is a particular convention for connecting
    with and exchanging data between two program
    processes within the same computer or across a
    network.
  • A socket is defined as "the endpoint in a
    connection." Sockets are created and used with a
    set of programming requests or "function calls"
    sometimes called the sockets application
    programming interface (API)

4
What are sockets?
  • A socket is a way of transferring data
  • The socket looks like a I/O file to your code
  • There are two forms of sockets
  • Client
  • Server
  • see photocopy of structure diagram for Server and
    Client

5
Types of socket
  • Stream
  • Datagram
  • Raw
  • Stream and Datagram sockets interface to the TCP
    and User Datagram Protocol(UDP) protocols
  • UDP is an alternative to the Transmission Control
    Protocol (TCP)
  • Raw sockets interface to the Internet Protocol(IP)

6
Vendors of sockets
  • Trumpet Winsock
  • Chameleon Sampler
  • NetCruiser
  • All the most popular sockets are in Windows 95
    onwards

7
Client Socket
  • There are four main operations
  • Connect to a remote Machine
  • Send Data
  • Receive Data
  • Close the connection

8
Server Socket
  • There are six main functions
  • A socket on a separate port
  • Will listen for action
  • Input or Output Streams
  • Will interact with Client
  • One or the other can close connection
  • Return to listening

9
Why are sockets used?
  • For simplicity
  • Easier access to the network
  • To set a type of protocol
  • More structure in programming

10
What do sockets do?
  • Create a way of data transfer
  • Give the programmer great power
  • Provide flexibility

11
How to use sockets
  • Set up Server Socket
  • Set up Client Socket
  • Once connection established
  • Create packet to send
  • Send the packet

12
How to use sockets
  • For the Server
  • Establish connection
  • Listen for packet
  • Send information
  • Both Client and Server listen

13
How to use sockets
  • Depending on programming
  • The Client will listen
  • The Server will listen
  • But the Client listens when told to
  • The server should listen automatically

14
Java Sockets
  • Within the Java Libraries
  • Networking Class - import java.net.
  • Data type Socket
  • import java.io.
  • import java.net.
  • public class SimpleServer
  • public final static int PORT 6776
  • protected ServerSocket listenSocket

15
Exceptions
  • When sending or receiving
  • Try
  • ServerSocket theServer new ServerSocket(444)
  • while(true)
  • Socket theConnection theServer.accept()
  • //blocks thread until accepted
  • PrintStream p new PrintStream(theConnection.ge
    tOutputStream() )
  • p.println(Welcome to my server, see you
    later)
  • theConnection.close()
  • catch(IOException e)
  • System.err.println(e)

16
Client Server
  • Connect to a remote machine
  • Socket remoteComputer
  • try
  • remoteComputer Socket(helix.nih.gov, 13)
  • // Ask for a socket to helix system time
  • catch(IOException e)

17
Streaming sockets
  • Server Client
  • Create a server socket
  • s new ServerSocket(5432)
  • Wait for a connection Open a connection
  • Socket conn s.accept() Socket soc new
    Socket(Manual, 5432)
  • Get an output Stream Get input Stream
  • Write data onto Stream Read data from input
    Stream
  • Close stream and socket Stream.close()
    soc.close()
  • Close output Stream,
  • connection and server sockets

18
Java Sockets
  • Demonstration now follows
  • This is a demo of two program processes within
    the same computer

19
Winsock
  • Winsock (Windows sockets)
  • Winsock is a programming interface and the
    supporting program that handles input/output
    requests for Internet applications in a Windows
    operating system.
  • It's called Winsock because it's an adaptation
    for Windows of the Berkeley UNIX sockets
    interface.

20
How Winsock work?
  • WinSock is a .DLL (Dynamic Link Library) and runs
    under Windows 3.x, Windows for Workgroups,
    Windows NT, and Windows 95. The WINSOCK.DLL is
    the interface to TCP/IP and, from there, on out
    to the Internet. (TCP/IP stands for "Transmission
    Control Protocol / Internet Protocol," the
    "language" that computers on the Internet use to
    communicate with each other.)

21
Winsock
  • Winsock runs between an application program such
    as a Netscape browser and the Internet program in
    your computer, TCP/IP.
  • A request flows in the following order
  • Netscape or other application
  • winsock.dll
  • TCP/IP
  • Modem or network card
  • The Internet and
    destination

22
Winsock
  • Winsock provides this interface for different
    versions of the Windows operating system. A
    comparable interface exists for Mac computers.
    Beginning with Windows 95, Winsock came as part
    of the operating system, but in earlier systems,
    a Winsock program had to be installed. UNIX
    systems do not require a Winsock equivalent
    because TCP/IP and its use of sockets was
    designed to run directly with UNIX application
    programs.

23
Winsock 2
  • Winsock 2 is a 32-bit version of Winsock.
  • In addition to TCP/IP, it provides an interface
    to a variety of protocols, including Novells
    Internetwork Packet Exchange (IPX)/Sequenced
    Packet Exchange(SPX), Integrated Services Digital
    Network(ISDN), wireless protocols, and Open
    Systems Interconnection (OSI) standard.
  • Winsock 2 is included in the latest versions fo
    the Windows operating systems.

24
Winsock 2
  • Netscape or other application
  • ws2-32.dll
    (Winsock 2)
  • TCP/IP (or certain other
    protocols)
  • Modem or
    network card
  • The Internet and
    destination

25
Winsock references
  • http//home.sol.no/hen/wsock.htm
  • http//www.faqs.org/faqs/windows/winsock-faq/
Write a Comment
User Comments (0)
About PowerShow.com