Socket Programming Present: KS Wu. 2003/10/6NTUEECS COBRA LAB 2 Outline UDP client/server communication Introduction of socket functions How MSN Messenger.

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.
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.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.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
תקשורת באינטרנט Tutorial 8. 2 n Socket programming u What is socket ? u Sockets architecture u Types of Sockets u The Socket system calls u Data Transfer.
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.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.
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.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
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.
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.
Introduction to Socket Programming Advisor: Quincy Wu Speaker: Kuan-Ta Lu Date: Nov. 25, 2010.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Chapter 2 Applications and Layered Architectures Sockets.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
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.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Chapter 2 Applications and Layered Architectures Sockets.
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,
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
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.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
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 Abstraction and Interprocess Communication
CS 1652 Jack Lange University of Pittsburgh
Elementary UDP Sockets
Socket Programming in C
Review: TCP Client-Server Interaction
Transport layer API: Socket Programming
Introduction to Socket Programming
UDP Sockets Programming
Socket Abstraction and Interprocess Communication
Socket Programming in C
Socket Abstraction and Interprocess Communication
Chapter 06. UDP Server/Client.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Internet Networking recitation #8
Presentation transcript:

Socket Programming Present: KS Wu

2003/10/6NTUEECS COBRA LAB 2 Outline UDP client/server communication Introduction of socket functions How MSN Messenger works

2003/10/6NTUEECS COBRA LAB 3 Outline UDP client/server communication Introduction of socket functions How MSN Messenger works

2003/10/6NTUEECS COBRA LAB 4 close() sendto() recvfrom() socket() bind() recvfrom() sendto() UDP Client UDP Server Wait for a request from client Process request Socket functions for UDP client-server

2003/10/6NTUEECS COBRA LAB 5 Outline UDP client/server communication Introduction of socket functions How MSN Messenger works

2003/10/6NTUEECS COBRA LAB 6 Socket functions socket() bind() recvfrom() sendto() closesocket()

2003/10/6NTUEECS COBRA LAB 7 socket Function int socket( int af, int type, int protocol ); Returns: nonnegative descriptor if OK, negative number on error sd = socket(AF_INET, SOCK_DGRAM, 0)

2003/10/6NTUEECS COBRA LAB 8 Parameters familyDescription AF_INETIPv4 protocols AF_INET6IPv6 protocols typeDescription SOCK_STREAMstream socket (TCP) SOCK_DGRAMdatagram socket (UDP) protocolDescription 0Normally set to 0

2003/10/6NTUEECS COBRA LAB 9 example int sd; sd = socket(AF_INET, SOCK_DGRAM, 0);

2003/10/6NTUEECS COBRA LAB 10 bind Function int bind( SOCKET sockfd, const struct sockaddr* name, int namelen ); Returns: 0 if OK, negative number on error

2003/10/6NTUEECS COBRA LAB 11 Parameters sockfd  Descriptor identifying an unbound socket. (returned by the socket function.) name  A pointer to a protocol-specific address namelen  Length of the value in the name parameter, in bytes.

2003/10/6NTUEECS COBRA LAB 12 example struct sockaddr_in serv; serv.sin_family = AF_INET; serv.sin_addr.s_addr = htonl(INADDR_ANY); serv.sin_port = htons(3000); bind(serv_sd, &serv, sizeof(serv));

2003/10/6NTUEECS COBRA LAB 13 recvfrom Function int recvfrom( SOCKET sockfd, char* buf, int len, int flags, struct sockaddr* from, int* fromlen ); Returns: # of bytes received (< len) if OK, 0 if connection has been gracefully closed, negative number on error

2003/10/6NTUEECS COBRA LAB 14 Parameters sockfd  Descriptor identifying a bound socket. buf  Buffer for the incoming data. len  Length of the data in buf, in bytes.

2003/10/6NTUEECS COBRA LAB 15 Parameters (cont.) flags  Indicator specifying the way in which the call is made. (usually set to 0) from  Optional pointer to a buffer in a sockaddr structure that will hold the source address upon return. fromlen  Optional pointer to the size, in bytes, of the from buffer.

2003/10/6NTUEECS COBRA LAB 16 example char mesg[MAXLINE]; n = recvfrom(sd, mesg, MAXLINE, 0, &cli, &cli_len);

2003/10/6NTUEECS COBRA LAB 17 sendto Function int sendto( SOCKET sockfd, const char* buf, int len, int flags, const struct sockaddr* to, int tolen ); Returns: # of bytes sent (< len) if OK, negative number on error

2003/10/6NTUEECS COBRA LAB 18 Parameters sockfd  Descriptor identifying a bound socket. buf  Buffer containing the data to be transmitted. len  Length of the data in buf, in bytes.

2003/10/6NTUEECS COBRA LAB 19 Parameters (cont.) flags  Indicator specifying the way in which the call is made. (usually set to 0) to  Optional pointer to a sockaddr structure that contains the address of the target socket. tolen  Size of the address in to, in bytes.

2003/10/6NTUEECS COBRA LAB 20 example sendto(sd, mesg, n, 0, &cli, cli_len);

2003/10/6NTUEECS COBRA LAB 21 closesocket Function int closesocket( SOCKET sockfd ); Returns: 0 if OK, negative number on error

2003/10/6NTUEECS COBRA LAB 22 Parameters sockfd  Descriptor identifying the socket to close.

2003/10/6NTUEECS COBRA LAB 23 example closesocket(sd);

2003/10/6NTUEECS COBRA LAB 24 Outline UDP client/server communication Introduction of socket functions How MSN Messenger works

2003/10/6NTUEECS COBRA LAB 25 How MSN Messenger works 2 phases  Authentication Phase  Instant Messaging Phase

2003/10/6NTUEECS COBRA LAB 26 How MSN Messenger works (cont.) Authentication Phase  logging into the MSN messenger server  Retrieve the friend list Instant Messaging Phase  Session-based  sending/accepting requests for an Instant Messaging session  sending/receiving messages

2003/10/6NTUEECS COBRA LAB 27 Server Components Dispatch Server Notification Server Switchboard Server

2003/10/6NTUEECS COBRA LAB 28 Dispatch server protocol version negotiation determination of which NS is associated with the client making a connection referring the client to the proper NS

2003/10/6NTUEECS COBRA LAB 29 Notification server authenticate, synchronize user properties exchange asynchronous event notifications

2003/10/6NTUEECS COBRA LAB 30 Switchboard server provide instant messaging sessions

2003/10/6NTUEECS COBRA LAB 31 Scenario DS Client 1. 確定版本 TCP (port 1863) version version! 2. 確定加密演算法 Policy?SP (MD5) 3. 認證使用者 Initiate infoChallenge infoPasswd + challenge userID + nickname

2003/10/6NTUEECS COBRA LAB 32 Scenario DS Client 4. 將 user 導到 NS NS addr:port NS Log in 5. 同步化使用者資訊 ( 更新 ) Latest properties? (cache) Yes No, update! 6. 下載新版 friend list List? List nickname nickname …

2003/10/6NTUEECS COBRA LAB 33 Scenario Client NS 7. 使用者狀態 State Online Offline Invisible OK! 8. 修改 friend list OK! (new SN) ADD/REM

2003/10/6NTUEECS COBRA LAB 34 Scenario Client A NS SS? 將 user 導到 SS SS addr SP (CHI) cookie 連結 SS 及做認證 SS userID cookie OK! 邀請使用者加入對談的 session I want to talk with B! SessionID 建立對談 Client B SessionID SS addr SP Cookie IDA nickname IDB cookie sessionID Index, # of participants 送出及時訊息 Hello!

2003/10/6NTUEECS COBRA LAB 35 Scenario Client A NSSS Client B 變更 Session 參與者 JOIN! Client C New userID nickname Left! Left userID Bye!

2003/10/6NTUEECS COBRA LAB 36 Download

2003/10/6NTUEECS COBRA LAB 37 Reference “Unix Network Programming” “WinSock 網路程式設計之鑰 ” aft.php aft.php

Thank You!