Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.

Slides:



Advertisements
Similar presentations
Socket Programming 101 Vivek Ramachandran.
Advertisements

Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Socket Programming CS3320 Fall 2010.
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
ISP – 9 th Recitation Socket programming – Client side.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
Remote Shell CS230 Project #4 Assigned : Due date :
Computer Networks : TP1 Prof. Dr. Amine Berqia and Prof. Dr. Fernando Lobo {bamine,
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.2. Windows Sockets.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Introduction to Socket
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Socket Programming Present: KS Wu. 2003/10/6NTUEECS COBRA LAB 2 Outline UDP client/server communication Introduction of socket functions How MSN Messenger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
Socket Abstraction and Interprocess Communication
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
Jim Fawcett CSE 687-OnLine – Object Oriented Design Summer 2017
Jim Fawcett CSE 775 – Distributed Objects Spring 2007
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
Socket Programming in C
TCP Sockets Programming
28.
Socket Abstraction and Interprocess Communication
Chapter 06. UDP Server/Client.
Socket Abstraction and Interprocess Communication
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Socket Abstraction and Interprocess Communication
Socket Programming(1/2)
Chapter 04. TCP Server/Client.
Internet Networking recitation #8
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to transmit application data across the wire, independent of the network protocol being used. Network Protocol Support in Windows Transmission Control Protocol/Internet Protocol (TCP/IP) is the dominant networking protocol suite in Enterprise networks and across the Internet. Yet, some other protocols are selectively supported as well.

Creating a TCP Stream Socket Application Use TCP to provide sequenced, reliable two-way connection- based byte streams. A TCP stream socket server application listens on the network for incoming client request packets. A TCP stream socket client application initiates communication with the server by sending a request packet. When the server receives the request, it processes it and responds. After this initial sequenced message exchange, client and server can exchange data. The following illustration shows the interaction between the TCP stream socket server and TCP stream socket client.

Creating a TCP Stream Socket Application – Cont’d There are two distinct types of socket network applications: Server and Client.

Creating a Socket The socket function creates a socket that is bound to a specific service provider. SOCKET socket( int af, // Address family specification. int type, // Type specification for the new socket int protocol // Protocol to be used with the socket that is specific // to the indicated address family. ); Return Values If no error occurs, socket returns a descriptor referencing the new socket. Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError. winSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); Server/Client

Binding a Socket The bind function associates a local address with a socket. int bind( SOCKET s, //Descriptor identifying an unbound socket. const struct sockaddr* name,//Address int namelen // Length in bytes ); Return Values If no error occurs, bind returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError sockaddr_in service; service.sin_family = AF_INET; service.sin_addr.s_addr = inet_addr( " " ); service.sin_port = htons( ); bind( m_socket, (SOCKADDR*) &service, sizeof(service) ); server

Listening on a Socket The listen function places a socket in a state in which it is listening for an incoming connection. int listen( SOCKET s, int backlog //Maximum length of the queue of pending connections ); If no error occurs, listen returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastErrorr. server

Connecting to a Socket client The connect function establishes a connection to a specified socket int connect( SOCKET s, const struct sockaddr* name, int namelen ); Parameters s [in] Descriptor identifying an unconnected socket. name [in] Name of the socket in the sockaddrr structure to which the connection should be established. namelen [in] Length of name, in bytes connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService))

Accepting Connection The accept function permits an incoming connection attempt on a socket. SOCKET accept( SOCKET s, struct sockaddr* addr, int* addrlen ); Parameters s [in] Descriptor that identifies a socket that has been placed in a listening state with the listen function. The connection is actually made with the socket that is returned by accept. addr [out] Optional pointer to a buffer that receives the address of the connecting entity addrlen [in, out] Optional pointer to an integer that contains the length of addr. server

Sending and Receiving Data The send function sends data on a connected socket. int send( SOCKET s, const char* buf, int len, int flags ); The recv function receives data from a connected or bound socket. int recv( SOCKET s, char* buf, int len, int flags ); bytesSent = send( ConnectSocket, sendbuf, strlen(sendbuf), 0 ); bytesRecv = recv( ConnectSocket, recvbuf, 32, 0 ); Server/Client

Sending and Receiving Data (Cont’d) Parameters s [in] Descriptor identifying a connected socket. buf [in] Buffer containing the outgoing/incoming data. len [in] Length of the data in buf, in bytes. flags [in] Indicator specifying the way in which the call is made. Return Values If no error occurs: send returns the total number of bytes sent, which can be less than the number indicated by len. recv returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError. Server/Client

Terminating the Communication The shutdown function disables sends or receives on a socket. int shutdown( SOCKET s, int how); How: Flag that describes what types of operation will no longer be allowed. SD_RECEIVE: subsequent calls to the recv function on the socket will be disallowed. SD_SEND: subsequent calls to the send function are disallowed. SD_BOTH: disables both sends and receives as described above. The shutdown function does not close the socket. Any resources attached to the socket will not be freed until closesocket is invoked. Server/Client

Terminating the Communication (cont’d) The closesocket function closes an existing socket. int closesocket( SOCKET s ); Remarks: The closesocket function closes a socket. Use it to release the socket descriptor s so that further references to s fail with the error. If this is the last reference to an underlying socket, the associated naming information and queued data are discarded. Any pending blocking, asynchronous calls issued by any thread in this process are canceled without posting any notification messages. An application should always have a matching call to closesocket for each successful call to socket to return any socket resources to the system. Server/Client