Tài liệu MỘT SỐ KHÁI NIỆM CƠ BẢN VỀ WINSOCK ppt

7 728 1
Tài liệu MỘT SỐ KHÁI NIỆM CƠ BẢN VỀ WINSOCK ppt

Đang tải... (xem toàn văn)

Thông tin tài liệu

M Ộ T S Ố KHÁI NI Ệ M C Ơ B Ả N v ề winsock : WinSock : WinSock API (Windows Sockets Application Programming Interface) là thư viện các hàm giao diện lập trình mạng cho Microsoft Windows. WinSock tương thích với họ nghi thức mạng TCP/IP. Socket : Socket là đầu (endpoint) trao đổi dữ liệu giữa các quá trình, qua đó các ứng dụng WinSock gởi / nhận dữ liệu qua mạng. Hai loại Socket : Stream Socket : Dựa trên nghi thức TCP ( Tranmission Control Protocol ), việc truyền dữ liệu chỉ thực hiện giữa hai quá trình đã thiết lập kết nối. Dữ liệu được truyền tin cậy, đúng trình tự và không lập lại. Dữ liệu được truyền như dòng liên tục các byte không phân biệt ranh giới các record Datagram Socket : Dựa trên nghi thức UDP ( User Datagram Protocol ), việc truyền dữ liệu không yêu cầu sự thiết lập kết nối giữa hai quá trình. Dữ liệu truyền không tin cậy, thể không đúng trình tự hoặc lập lại. Dữ liệu được truyền như dòng các record. Port : Port xác định duy nhất một quá trình trên một máy trong mạng. Một TCP/IP Socket gồm một địa chỉ IP kết hợp với một port ? xác định duy nhất một quá trình trên mạng. Một số port dành riêng : UDP Ports : 0 Reversed 7 Echo 37 Time 42 Name Server 53 Domain Name Server 69 Trivial File Transfer Program ( TFTP ) 514 System Log . . . . . . . . . . TCP Ports : 0 Reversed 1 TCP Multiplexor 20 FTP_ Data Connection 21 FTP_ Command Connection 23 TELNET 25 SMTP 42 Name Server 53 Domain Name Server 79 Finger_ find a active user . . . . . . . . . . . . . . . . . . . . . Lập trình winsock Các file cần thiết : WINSOCK.DLL hay WSOCK32.DLL ( tuỳ version 16 hay 32 bit của Windows ). WINSOCK.LIB hay WSOCK32.LIB. WINSOCK.H. Giới thiệu một số hàm của WinSock: Dưới đây chỉ giới thiệu chức năng của một số hàm WinSock, không trình bày prototype của các hàm Các hàm khởi động WinSock : Dùng để khởi đầu và kết thúc quá trình sử dụng WinSock. WSAStartup() : Khởi động WinSock. WSACleanup() : Kết htúc WinSock. WSAGetLastError() : Lấy mã sai vừa xảy ra. Các hàm Socket : Dùng để thiết lập quá trình trao đổi dữ liệu trên mạng. socket() : tạo socket truyền dữ liệu. bind() : định danh cho socket vừa tạo (gán port cho socket). listen() : lắng nghe kết nối. accept() : chấp nhận kết nối từ client. connect() : kết nối với server. send(), recv() : gởi, nhận dữ liệu với stream socket. sendto(), recvfrom() : gởi, nhận dữ liệu với datagram socket. . . . . . . . . Các hàm khác : inet_addr() : chuyển từ địa chỉ IP dạng số thập phân chấm sang địa chỉ internet. inet_ntoa() : ngược lại. gethostname() : cho tên máy hiện hành. gethostbyname(),WSAAsyncGetHostByName() : cho địa chỉ IP ứng với tên máy. gethostbyaddr(),WSAAsyncGetHostByAddr() : cho tên máy ứng với địa chỉ IP. . . . . . . . . WinSock error: Lỗi khi send data WSANOTINITIALISED A successful AfxSocketInit must occur before using this API. WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed. WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set. WSAEINPROGRESS A blocking Windows Sockets operation is in progress. WSAEFAULT The lpBuf or lpSockAddr parameters are not part of the user address space, or the lpSockAddr argument is too small (less than the size of a SOCKADDR structure). WSAENETRESET The connection must be reset because the Windows Sockets implementation dropped it. WSAENOBUFS The Windows Sockets implementation reports a buffer deadlock. WSAENOTCONN The socket is not connected (SOCK_STREAM only). WSAENOTSOCK The descriptor is not a socket. WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not of type SOCK_STREAM. WSAESHUTDOWN The socket has been shut down; it is not possible to call SendTo on a socket after ShutDown has been invoked with nHow set to 1 or 2. WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block. WSAEMSGSIZE The socket is of type SOCK_DGRAM, and the datagram is larger than the maximum supported by the Windows Sockets implementation. WSAECONNABORTED The virtual circuit was aborted due to timeout or other failure. WSAECONNRESET The virtual circuit was reset by the remote side. WSAEADDRNOTAVAIL The specified address is not available from the local machine. WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket. WSAEDESTADDRREQ A destination address is required. WSAENETUNREACH The network cannot be reached from this host at this time. Lỗi khi receive data WSANOTINITIALISED A successful AfxSocketInit must occur before using this API. WSAENETDOWN The Windows Sockets implementation detected that the network subsystem failed. WSAENOTCONN The socket is not connected. WSAEINPROGRESS A blocking Windows Sockets operation is in progress. WSAENOTSOCK The descriptor is not a socket. WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not of type SOCK_STREAM. WSAESHUTDOWN The socket has been shut down; it is not possible to call Receive on a socket after ShutDown has been invoked with nHow set to 0 or 2. WSAEWOULDBLOCK The socket is marked as nonblocking and the Receive operation would block. WSAEMSGSIZE The datagram was too large to fit into the specified buffer and was truncated. WSAEINVAL The socket has not been bound with Bind. WSAECONNABORTED The virtual circuit was aborted due to timeout or other failure. WSAECONNRESET The virtual circuit was reset by the remote side. Trình tự thiết lập quá trình trao đổi dữ liệu : Dùng Stream Socket : Dùng Datagram Socket : PcLeHoan 1996 - 2002 Mirror : http://www.pclehoan.com Mirror : http://www.lehoanpc.net Mirror : http://www.ktlehoan.com . nhất một quá trình trên một máy trong mạng. Một TCP/IP Socket gồm một địa chỉ IP kết hợp với một port ? xác định duy nhất một quá trình trên mạng. Một số. thiệu một số hàm của WinSock: Dưới đây chỉ giới thiệu chức năng của một số hàm WinSock, không trình bày prototype của các hàm Các hàm khởi động WinSock

Ngày đăng: 23/12/2013, 05:18

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan