Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.

Slides:



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

Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Network Programming UNIX Internet Socket API. Everything in Unix is a File –When Unix programs do any sort of I/O, they do it by reading or writing to.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
CS Computer Networks I Georgia Tech CS Computer Networks 1: Sockets Programming Adapted from slides by Professor Patrick Traynor.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
1 Programming with TCP/IP Ram Dantu. 2 Client Server Computing r Although the Internet provides a basic communication service, the protocol software cannot.
UNIX Socket Programming CS 6378
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
Introduction to Socket Programming Advisor: Quincy Wu Speaker: Kuan-Ta Lu Date: Nov. 25, 2010.
Sirak Kaewjamnong Computer Network Systems
1 Internet Socket programming Behzad Akbari. 2 Sharif University of Technology, Kish Island Campus What is an API? API – stands for Application Programming.
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
CS x760 Computer Networks1 Socket Programming. CS 6760 Computer Networks2 Socket Programming  What is a socket?  Using sockets  Types (Protocols) ‏
1 Introduction to Computer Networks Ilam University By: Dr. Mozafar Bag Mohammadi Sockets.
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.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
The Sockets Library and Concepts Rudra Dutta CSC Spring 2007, Section 001.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Practical Sockets and Threads Derek Weitzel. Windows Threads Concurrent processing Concurrent processing Windows Create Thread Windows Create Thread HANDLE.
Socket address structures Byte ordering IP address conversion
UNIX Internet Socket API
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
CSCI 183/183W/232: Computer Networks Socket API1 Today’s Agenda 1.Overview of Socket Programming 2.Project Description.
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 Péter Verhás August 2002
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
Network Programming with Sockets
Review: TCP Client-Server Interaction
Introduction to Computer Networks
Transport layer API: Socket Programming
Socket Programming What is a socket? Using sockets Types (Protocols)
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
Introduction to Socket Programming
28.
Socket Programming.
Socket Programming What is a socket? Using sockets Types (Protocols)
Socket Programming(1/2)
Socket Programming What is a socket? Using sockets Types (Protocols)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Socket Programming What is a socket? Using sockets Types (Protocols)
Sockets.
CSI 4118 – UNIVERSITY OF OTTAWA
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Winsock programming

 TCP/IP UDP TCP  Winsock #include wsock32.lib

 int WSAStartup( WORD wVersionRequested, LPWSADATA lpWSAData );  int WSACleanup (void);  int WSAGetLastError (void); #define h_errno WSAGetLastError()

 SOCKET socket( int af, int type, int protocol );  typedefu_int SOCKET;  Address families #define AF_INET 2 /* internetwork: UDP, TCP, etc. */  Protocol families, same as address families for now. #define PF_INET AF_INET  Types #define SOCK_STREAM 1 /* stream socket */ #define SOCK_DGRAM 2  int bind( SOCKET s, const struct sockaddr FAR *name, int namelen );  int listen( SOCKET s, int backlog );  SOCKET accept( SOCKET s, struct sockaddr FAR *addr, int FAR *addrlen );  int connect( SOCKET s, const struct sockaddr FAR *name, int namelen ); socket descriptor Protocol Local IP address Local port Remote IP address Remote port

 typedef struct sockaddr_in SOCKADDR_IN;  struct sockaddr_in { short sin_family;// 2 u_short sin_port;// 2 struct in_addr sin_addr; // 4 char sin_zero[8];// 8 };  struct in_addr { union { struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;// 4 struct { u_short s_w1,s_w2; } S_un_w;// 4 u_long S_addr;// 4 } S_un;  #define s_addrS_un.S_addr  #define INADDR_ANY (u_long)0x  struct sockaddr { u_short sa_family; /* address family */ char sa_data[14]; /* up to 14 bytes of direct address */ };

 Data conversion functions  char FAR * inet_ntoa( struct in_addr in );  unsigned long inet_addr( const char FAR *cp );  u_long htonl( u_long hostlong );  u_long ntohl( u_long netlong );  u_short ntohs( u_short netshort );  u_short htons( u_short hostshort );  Socket information functions  int getpeername( SOCKET s, struct sockaddr FAR *name, int FAR *namelen );  int getsockname( SOCKET s, struct sockaddr FAR *name, int FAR *namelen );

 int send( SOCKET s, const char FAR *buf, int len, int flags );  int recv( SOCKET s, char FAR *buf, int len, int flags );  int sendto( SOCKET s, const char FAR *buf, int len, int flags, const struct sockaddr FAR *to, int tolen );  int recvfrom( SOCKET s, char FAR* buf, int len, int flags, struct sockaddr FAR *from, int FAR *fromlen );

 Select  int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds, fd_set FAR *exceptfds, const struct timeval FAR *timeout);  #define FD_SETSIZE 64  typedef struct fd_set { u_int fd_count; /* how many are SET? */ SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */ } fd_set;  typedef struct fd_set FD_SET;  struct timeval { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ };  typedef struct timeval TIMEVAL;  FD_CLR(fd, set)  FD_SET(fd, set)  FD_ZERO(set)  FD_ISSET(fd, set)

References  WinSock 網路程式設計之鑰  親手打造網際網路四大服務  Unix Socket Programming  MSDN

Exercise  File transfer Send a file to server or receive a file from server Using TCP Read until a block Write until a block Timeout