【正文】
the client and the server 重復服務器在一個時間只能和一個客戶程序建立連接,它對多個客戶程序的處理是采用循環(huán)的方式重復進行,因此叫重復服務器。 例如: memcmp(amp。 例:假如一個程序要使用 Socket,那么程序代碼如下 wVersionRequested = MAKEWORD( 2, 1 )。 ClientServer模式的產(chǎn)生原因及其功能 Socket接口及其在 ClientServer模式中的執(zhí)行模式 作業(yè) 。wsaData )。y, 10 ) 地址轉(zhuǎn)換函數(shù) atoi() 網(wǎng)絡信息查詢函數(shù) Gethostbyname() 關(guān)于主機的信息 地址長度 WinSock Socket接口是網(wǎng)絡編程(通常是 TCP/IP協(xié)議,也可以是其他協(xié)議)的 API。 附錄 1. Memset: 將一個指明的字節(jié)數(shù)設置為一個值,第一個變量是指針,它指向目的地,第二個變量是它的值,第三個變量是字節(jié)數(shù)。常用的調(diào)用有 send()和 recv()。 參數(shù) s a d d r e s s l e n是以字節(jié)形式說明的服務器地址的長度。 The Accept Procedure The accept function is called by a TCP server to remove the first connection request from the corresponding queue. If there are no requests (the queue is empty), the accept function is put to sleep. a c c e p t調(diào)用的形式為: newsock = accept( socket, caddress, caddresslen) 參數(shù) s o c k e t是服務器已經(jīng)創(chuàng)建并綁定于指定協(xié)議端口的插口描述符。為保證數(shù)據(jù)的正確性,在網(wǎng)絡協(xié)議中須指定網(wǎng)絡字節(jié)順序。例如: IPPROTO_IGMP IPPROTO_IP IPPROTO_ICMP The Bind Procedure The bind function binds a socket to a local socket address by adding the local socket address to an already created socket. 其調(diào)用格式如下: bind( socket, localaddr, addrlen) Returns 0 if successful。文件傳送協(xié)議( FTP)即使用流式插口。 由于 TCP/IP傳輸層的兩個協(xié)議 TCP和 UDP是完全獨立的兩個軟件模塊,因此各自的端口號也相互獨立, 如 TCP有一個 255號端口, UDP也可以有一個255號端口,二者并不沖突。 Sockets, Descriptors, And work I/O Socket munication also uses the descriptor approach. Before an application can use protocols to municate,the application must request the operating system to create a socket that will be used for munication. The system returns a small integer descriptor that identifies the socket. In a Unix implementation,sockets are pletely integrated with other I/o. A single application can be written that transfers data to an arbitrary location. 網(wǎng)絡中可以被命名和尋址的通信端口,是操作系統(tǒng)可分配的一種資源。 由于每個進程都在自己的地址范圍內(nèi)運行,為保證兩個相互通信的進程之間既互不干擾又協(xié)調(diào)一致工作,操作系統(tǒng)為進程通信提供了相應設施: 如 UNIX BSD中的管道( pipe)、命名管道( named pipe)和軟中斷信號( signal),UNIX system V的消息( message)、共享存儲區(qū)( shared memory)和信號量( semaphore)等,但都僅限于用在本機進程之間通信。 UNIX系統(tǒng)的 I/O命令集,其模式為打開一讀 /寫一關(guān)閉( openwritereadclose)。Computer Networks and Inters 《 計算機網(wǎng)絡與因特網(wǎng) 》 課件 PART IV Network Applications Chapter 27 The Socket Interface Socket 接口 Introduction The interface between an application and protocol software. How an application uses protocol