Sockets The Standard Network Programming API Agenda Evolution Evolution API Components (Sockets/Winsock) API Components (Sockets/Winsock) Protocol Configuration.

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.
Socket Programming Application Programming Interface.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Computer Networks Sockets.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
1 Pertemuan 10 Non Blocking Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Tutorial 8 Socket Programming
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.
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
UNIX Sockets COS 461 Precept 1.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
ECE 4110 – Internetwork Programming Client-Server Model.
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.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
LWIP TCP/IP Stack 김백규.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全.
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.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.2. Windows Sockets.
Outline Socket programming with Windows OSSocket programming with Windows OS C++ UDPSocket classC++ UDPSocket class Socket programming with Windows OSSocket.
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.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
1 WNT Low Level Network Interfaces Tutorial NT015 Copyright, 1997 ©Mentec Inc Paul Fix Mentec Inc.
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 Lab 1 1CS Computer Networks.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
Socket Programming.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Berkeley Socket Abstraction
UNIX Sockets Outline UNIX sockets CS 640.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Sockets and Beginning Network Programming
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
UNIX Sockets COS 461 Precept 1.
Jim Fawcett CSE 687-OnLine – Object Oriented Design Summer 2017
Week 13 - Friday CS222.
Jim Fawcett CSE 775 – Distributed Objects Spring 2007
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Interprocess Communication
Server-side Programming CSE 333 Autumn 2018
Server-side Programming CSE 333 Summer 2018
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 Inter-process Communication
Socket Abstraction and Inter-process Communication
Windows sockets Iveta LenčiauskaitE.
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Sockets The Standard Network Programming API

Agenda Evolution Evolution API Components (Sockets/Winsock) API Components (Sockets/Winsock) Protocol Configuration Protocol Configuration Tools Tools

Evolution Mid 80’s  Berkley Sockets 1991  birds-of-a-feather 1992  Winsock  Winsock 1.1 Now  2.0+

Winsock vs. “Berkley” Sockets Berkley Sockets were the original socket implementation Berkley Sockets were the original socket implementation Berkley Sockets == X-Platform Berkley Sockets == X-Platform Work on any TCP/IP stack Work on any TCP/IP stack Unix / Linux Unix / Linux Consoles Consoles Mac Mac Windows Windows Winsock specific begins with “WSA” Winsock specific begins with “WSA” Winsock specific Winsock specific WSAStartup() WSAStartup() WSAAsynch…() WSAAsynch…() Generic Sockets Generic Sockets socket() socket() recvfrom() recvfrom()

Winsock 2.0 QoS (Quality of Service) Reserve bandwidth Multicast Conserves bandwidth by allowing send lists. One packet to multiple recipients. Requires multicast aware hardware Overlapped I/O High performance I/O model !!! NOT PORTABLE !!! IPv6 (making provisions for) Expanded address space IPSec (Data Encryption)

File I/O “Stream” Similarities Winsock 2.n added “Unified I/O” Winsock 2.n added “Unified I/O” MSDN mentions deprecation MSDN mentions deprecation Socket Handle == File Handle Socket Handle == File Handle CreateFile(…) CreateFile(…) ReadFile(…) / WriteFile(…) ReadFile(…) / WriteFile(…) CloseFile(…) CloseFile(…) Serial I/O same Serial I/O same Com Handle == File Handle Com Handle == File Handle

Sockets API Components InitConnectServiceDisconnectDeInit

Initialization Winsock Specific Winsock2.h Winsock2.h Include this header Include this header WS2_32.lib WS2_32.lib Link to this library Link to this library WSAStartup ( in ReqVer, out VerInfo ) WSAStartup ( in ReqVer, out VerInfo ) Can succeed even if is doesn’t support your requested version in it’s entirety. BAH!!! Can succeed even if is doesn’t support your requested version in it’s entirety. BAH!!! View VerInfo to make certain the version. View VerInfo to make certain the version. Should provision for fallback. Should provision for fallback. WSACleanup () WSACleanup () Close all sockets before calling this function. Close all sockets before calling this function. Make sure no pending blocking sockets. Make sure no pending blocking sockets. WSAGetLastError () WSAGetLastError () Call this to determine extended error information on error from any Winsock method. Call this to determine extended error information on error from any Winsock method. Does not work until successful return from WSAStartup (). Does not work until successful return from WSAStartup ().

Domain Name Resolution Functions gethostbyname (char *domainName) gethostbyname (char *domainName) Deprecated Deprecated WSAAsyncGetHostByName (char *) WSAAsyncGetHostByName (char *) Deprecated Deprecated getaddrinfo ( char *domainName, …) getaddrinfo ( char *domainName, …) New to Winsock 2 New to Winsock 2 Reverse lookups also available Reverse lookups also available IP  Domain IP  Domain getnameinfo() Winsock 2 getnameinfo() Winsock 2 gethostbyaddr() Winsock 1 (deprecated) gethostbyaddr() Winsock 1 (deprecated)

Create Socket Specifying Protocol socket ( in family, in stream, in protocol) socket ( in family, in stream, in protocol) Address Family: Address Family: AF_INET AF_INET Stream: (Connected or Connectionless) Stream: (Connected or Connectionless) SOCK_STREAM SOCK_STREAM SOCK_DGRAM SOCK_DGRAM SOCK_RAW SOCK_RAW Protocol: Protocol: IPPROTO_TCP IPPROTO_TCP IPPROTO_UDP IPPROTO_UDP Returns an unconnected handle to a socket. Returns an unconnected handle to a socket. closesocket (socket) closesocket (socket) Closes connection Closes connection Releases the resources Releases the resources

Connect Initiate a connection connect ( socket, addr, addrlen) connect ( socket, addr, addrlen) socket = handle created with call to ‘socket’ socket = handle created with call to ‘socket’ addr = port & IP of place to connect. addr = port & IP of place to connect. must specify the address family in the addr struct. must specify the address family in the addr struct. addrlen = sizeof(addr). addrlen = sizeof(addr). WSAConnect(…) WSAConnect(…) Supports Quality of Service. Supports Quality of Service. Facilitates initial data packet transfer upon connect. Facilitates initial data packet transfer upon connect.

Bind Specify “Incoming” Address bind ( in socket, in address, in sizeof(address) ) bind ( in socket, in address, in sizeof(address) ) Socket = socket handle Socket = socket handle Address Address family = AF_INET family = AF_INET sin_port = htons( port # ) sin_port = htons( port # ) sin_addr.s_addr = htonl (ADDR_ANY) sin_addr.s_addr = htonl (ADDR_ANY) Can specify IP if more than one NIC and want specific one. Can specify IP if more than one NIC and want specific one. Fails if IP/port combo in use. Keep track of ports in use in app and try unused one. May have to cycle through a few. Fails if IP/port combo in use. Keep track of ports in use in app and try unused one. May have to cycle through a few. Implicit bind done on connect(). You must bind before an accept(). Implicit bind done on connect(). You must bind before an accept(). Cannot rebind. Cannot rebind.

Listen Listen for a connection requests listen ( in socket, in backlog ) listen ( in socket, in backlog ) socket socket Backlog Backlog # of pending connections allowed before additional connections are refused. # of pending connections allowed before additional connections are refused. Call listen() once to set listening state. Call listen() once to set listening state. Returns immediately. Returns immediately. To stop listening on the socket, close it. To stop listening on the socket, close it. closesocket ( socket ). closesocket ( socket ).

Accept Accepting a connection newSock accept ( in socket, out addr, in sizeof(addr)) newSock accept ( in socket, out addr, in sizeof(addr)) Socket Socket One you are listening on. One you are listening on. newSocket newSocket New socket created by the accept() method. Use this socket to send() / recv() on the new connection. New socket created by the accept() method. Use this socket to send() / recv() on the new connection. NOTE NOTE This is NOT the socket you passed to listen(). It is a brand spanking new socket. This is NOT the socket you passed to listen(). It is a brand spanking new socket. Addr Addr Address of connection accepted (filled out by the accept function). Address of connection accepted (filled out by the accept function). Steps Steps socket () socket () bind () bind () listen () listen () accept () accept () Loop on accept() until you have all the connections you want, then close the socket passed to listen(). Loop on accept() until you have all the connections you want, then close the socket passed to listen().

Send Sending Data send ( socket, buff, bufflen, flags) send ( socket, buff, bufflen, flags) Flags Flags MSG_OOB MSG_OOB Priority message. Can’t use with UDP Priority message. Can’t use with UDP Used with connection based e.g., TCP Used with connection based e.g., TCP sendto (…, addr, sizeof(addr)) sendto (…, addr, sizeof(addr)) Addr = address to send to. Overrides bind() if socket was bound. Addr = address to send to. Overrides bind() if socket was bound. Used with connectionless e.g., UDP Used with connectionless e.g., UDP WSASend (ditto send, overlap struct, OL funk) WSASend (ditto send, overlap struct, OL funk) Use with overlapped I/O Use with overlapped I/O WSASendTo (…) WSASendTo (…) Use with overlapped I/O Use with overlapped I/O

Receive Receiving Data recv (sock, buff, bufflen, flags) recv (sock, buff, bufflen, flags) Buff = incoming data Buff = incoming data Bufflen = number of bytes in buffer or bytes to receive (whichever is less) Bufflen = number of bytes in buffer or bytes to receive (whichever is less) Flags Flags MSG_PEEK MSG_PEEK Leave data in system buffers. Inefficient Leave data in system buffers. Inefficient MSG_OOB MSG_OOB Get out-of-band packets Get out-of-band packets recvfrom (…) recvfrom (…) UDP version UDP version WSARecv (…) WSARecv (…) Overlapped version Overlapped version WSARecvFrom (…) WSARecvFrom (…) Overlapped version Overlapped version WSARecvEx (…) WSARecvEx (…) Adds protocol for large messages via. MSG_PARTIAL notification. Normally handled by application with standard socket’s recv(). Adds protocol for large messages via. MSG_PARTIAL notification. Normally handled by application with standard socket’s recv(). Not used with overlapped I/O. Not used with overlapped I/O.

Protocol Configuration Socket Options I/O Control

Socket Options (get/set)sockopt (sock, sol*, so*, val, sizeof(val)) (get/set)sockopt (sock, sol*, so*, val, sizeof(val)) “sol” socket option level “sol” socket option level SOL_SOCKET SOL_SOCKET Generic Level Generic Level IPPROTO_TCP IPPROTO_TCP TCP/IP specific TCP/IP specific “so” Common Sock Options “so” Common Sock Options SO_BROADCAST SO_BROADCAST SO_KEEPALIVE SO_KEEPALIVE SO_MAX_MSG_SIZE SO_MAX_MSG_SIZE SO_RCVBUF SO_RCVBUF SO_RCVTIMEO SO_RCVTIMEO SO_SNDBUF SO_SNDBUF Much more Much more Multicast group membership management Multicast group membership management

I/O Control ioctlsocket (sock, command, arg) ioctlsocket (sock, command, arg) FIONBIO FIONBIO On/Off non-blocking mode (blocking is default) On/Off non-blocking mode (blocking is default) Additional Multicast configuration Additional Multicast configuration Set Keep Alive interval Set Keep Alive interval Flush send buffer Flush send buffer And more… And more… WSAIoctl (…) WSAIoctl (…) Overlapped version Overlapped version

Tools Making Development EasierGetting the Job Done!!!

Tools Shims Shims DLL that sits between Winsock and IP stack, or IP stack and device driver. DLL that sits between Winsock and IP stack, or IP stack and device driver. Let’s you monkey with everything. Let’s you monkey with everything. Hacker tool Hacker tool Ping Ping App that sends an ICMP message to an IP. App that sends an ICMP message to an IP. Reports round trip time. Reports round trip time. Good for determining average latency and general internet connection state. Good for determining average latency and general internet connection state. Trace Route Trace Route App that sends a packet to an IP. App that sends a packet to an IP. Reports hops and time between hops. Reports hops and time between hops. Good for locating problematic net hardware Good for locating problematic net hardware NetStat NetStat App that reports all packet activity App that reports all packet activity Ipconfig/winifcfg Ipconfig/winifcfg App that reports local IP addresses App that reports local IP addresses Sniffers Sniffers Similar to SHIMS, but often a piece of hardware Similar to SHIMS, but often a piece of hardware Can sit between NIC and cable, or attach to cable anywhere Can sit between NIC and cable, or attach to cable anywhere Expensive equipment, time consuming to learn and use effectively Expensive equipment, time consuming to learn and use effectively

Socket Wrappers Platform SDKs Platform SDKs Special O/S specific e.g. xbox achievement, session, … Special O/S specific e.g. xbox achievement, session, … Speech Speech Middle Ware Middle Ware Server Components Server Components Lobby Client Lobby Client Tested Architecture Tested Architecture High Performance (really?) High Performance (really?) Encryption Schemes Encryption Schemes Compression Schemes Compression Schemes Standard/Flexible Message Format Standard/Flexible Message Format X-Platform X-Platform Flexible API Flexible API See references link on class web site for venders See references link on class web site for venders