Download IT COOKBOOK

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
IT COOKBOOK
Windows Network Programming
-0-
Chapter 01.
Intro. to Network and
Socket Programming
 Goal
•
•
•
•
IT COOKBOOK
TCP/IP Protocol
Basic concept of socket
Windows socket overview
Writing and executing of Windows socket
application
-2-
 Internet Configuration
IT COOKBOOK
①
Router
End System
(PC, PDA, ...)
②
③
Router
④
End System
(PC, PDA, ...)
-3-
 TCP/IP Protocol
IT COOKBOOK
End System
End System
Application
Application
TCP/IP Protocol
(OS)
TCP/IP Protocol
(OS)
Router
Router
-4-
 TCP/IP Protocol Structure (1/6)
IT COOKBOOK
• TCP/IP Protocol Structure
– Layering Structure
TELNET, FTP, HTTP,
SMTP, MIME, SNMP, ...
Application Layer
Transport Layer
TCP, UDP
Internet Layer
IP
Device Driver
Network Hardware
Network Access Layer
-5-
 TCP/IP Protocol Structure (2/6)
IT COOKBOOK
• Network access layer
– Role
• Data transmission through physical network
– Components
• Network hardware + device driver
– Addressing
• physical address(MAC address)
• Command: ‘ipconfig /all’
– Example
• Ethernet
-6-
 TCP/IP Protocol Structure(3/6)
IT COOKBOOK
• Internet layer
– Role
• Packet routing
– Addressing
• IP address
• Transport layer
– Role
• Data transfer to end system
– Addressing
• port number
– Examples
• TCP(Transmission Control Protocol), UDP(User Datagram
Protocol)
-7-
 TCP/IP Protocol Structure(5/6)
IT COOKBOOK
• TCP and UDP
TCP
UDP
Connection-oriented Protocol
- Data transfer after connection setup
Connectionless Protocol
- Data transfer winthout connection
Byte-stream service
Datagram service
Reliable data transfer
- Retransmission mechanism
Unreliable data transfer
- No retransmission mechanism
1 to 1 communication(unicast)
1 to 1 communication(unicast)
1 to N communication (broadcast),
N to N Communication (multicast)
-8-
 TCP/IP Protocol Structure(6/6)
IT COOKBOOK
• Application layer
– Role
• Including some application protocol and services
• Providing various application service
– Examples
• Telnet, FTP, HTTP, SMTP etc.
-9-
 Packet transfer Principle (1/5)
IT COOKBOOK
• Packet
– Control information defined by each protocol (IP
address, port number, error check code etc.) + data
– Depending on the location, header and trailer
- 10 -
 Packet transfer Principle(2/5)
IT COOKBOOK
• Packet transfer at sender side
Application
data
TCP Header
data
IP Header TCP Header
data
TCP
IP
Ethernet
Ethernet
Header
IP
Header
TCP
Header
- 11 -
data
Ethernet trailer
 Packet transfer Principle(3/5)
IT COOKBOOK
• Packet transfer at receiver side
Application
data
TCP
IP
Ethernet
Ethernet
Header
TCP Header
data
IP Header TCP Header
data
IP
Header
TCP
Header
- 12 -
data
Ethernet trailer
 Packet transfer Principle(5/5)
IT COOKBOOK
• Packet transfer using Internet protocol
Application Layer
Application Layer
Transport Layer
Transport Layer
Internet Layer
Internet Layer
Internet Layer
Internet Layer
Network Access Layer
Network Access Layer
Network Access Layer
Network Access Layer
End system
Router
Router
End system
- 13 -
 IP address and port number (1/3)
IT COOKBOOK
• IP 주소
– Unique identifier of a internet host
– IPv4: 32bit, IPv6: 128bit
• example) 147.46.114.70
• example) loopback address: 127.0.0.1
• Port number
– Unique process identifier
- 14 -
 IP address and port number (2/3)
IT COOKBOOK
• IP address and port number
process
process
process
Port number(0~65535)
TCP
UDP
IP
IP address
- 15 -
 Client/server model
IT COOKBOOK
• Client/server Model
• Server first executed
• When client send the request, server processes the request
• Example: web client/server
Server
Client
connecting
waiting
- 16 -
 socket concept (1/5)
IT COOKBOOK
• Three points of view
① Data type
② communication end-point
③ Network programming interface
- 17 -
 socket concept(2/5)
IT COOKBOOK
• Data type
– Each of client and server is identified by a separate
socket address
– Example of socket address data type
• Struct sockaddr_in, in_addr
// file creation
// socket creation
int fd = open("myfile", ...);
SOCKET sock = socket(...);
...
...
read(fd, ...) // Reading
recv(sock, ...) // Receive
write(fd, ...) // Writing
send(sock, ...) // Send
- 18 -
 socket concept(3/5)
IT COOKBOOK
• Communication end-point
– Socket requires three components
• protocol(TCP/IP, UDP/IP)
• sender IP address, sender port number
• receiver IP address, receiver port number
- 19 -
 socket concept(4/5)
IT COOKBOOK
• Communication end-point(cont’d)
client
server
send (sock, ...)
recv (sock, ...)
data
<server socket>
<client socket>
• protocol: TCP/IP
• IP address: 147.46.114.70
• port number: 12023
• protocol : TCP/IP
• IP address: 61.72.244.22
• port number: 9001
- 20 -
 socket concept(5/5)
IT COOKBOOK
• Network programming interface
– Socket is the interface between application layer and
transport layer in TCP/IP protocol stack
application
application
application
Socket interface
TCP
UDP
ICMP, IGMP
IP
- 21 -
 Windows sockets (1/3)
IT COOKBOOK
• Windows Sockets, Winsock
- Originate by Berkeley Software Distribution UNIX
- Included as API(Application Programming Interface)
since Windows 95 version
- 22 -
 Windows sockets(2/3)
IT COOKBOOK
• Winsock supported by windows version
OS
Winsock ver.
Windows 95
1.1 (2.2)
Windows 98/Me, Windows NT/2000/XP/2003
2.2
Windows CE
1.1 (2.2)
• Supported protocols
– TCP/IP, IPv6(windows XP or above), IrDA(windows 98
or above), Bluetooth(windows XP SP2 or above),
IPX/SPX, ATM, DECNet, TP4(Not supported since
windows 2000), DLC(TP4(Not supported since
windows XP),
NetBEUI(Not supported since windows XP)
- 23 -
 Windows sockets(3/3)
IT COOKBOOK
• Structure
Winsock 2.x
Application
Winsock 1.x
Application
Winsock 1.x API
WINSOCK.DLL (16 bit)
WSOCK32.DLL (32 bit)
Winsock 1.x Extended API
MSWSOCK.DLL
Winsock 2.x API
WS2_32.DLL (32 bit)
TCP/IP
IrDA
Bluetooth
- 24 -
IPX/SPX
...
 Winsock application practice
IT COOKBOOK
• Source code:
– ftp://203.241.187.71
• Sample Winsock application(server.cpp)
- 25 -
Related documents