亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? rhl54.htm

?? linux的初學電子書
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<HTML>

<HEAD>

<TITLE>Red Hat Linux Unleashed rhl54.htm </TITLE>

<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm">

<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/htindex.htm">

<LINK REL="Next" HREF="rhl55.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl55.htm">

<LINK REL="Previous" HREF="rhl53.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl53.htm"></HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<A NAME="I0"></A>

<H2>Red Hat Linux Unleashed rhl54.htm</H2>

<P ALIGN=LEFT>

<A HREF="rhl53.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl53.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>

<A HREF="rhl55.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl55.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>


<HR ALIGN=CENTER>

<P>

<UL>

<UL>

<UL>

<LI>

<A HREF="#E68E415" >Ports and Sockets</A>

<LI>

<A HREF="#E68E416" >Socket Programming</A>

<UL>

<LI>

<A HREF="#E69E535" >socket()</A>

<LI>

<A HREF="#E69E536" >The bind() System Call</A>

<LI>

<A HREF="#E69E537" >The listen() System Call</A>

<LI>

<A HREF="#E69E538" >The accept() System Call</A>

<LI>

<A HREF="#E69E539" >The connect() System Call</A>

<LI>

<A HREF="#E69E540" >Connectionless Socket Programming</A></UL>

<LI>

<A HREF="#E68E417" >Record and File Locking</A>

<LI>

<A HREF="#E68E418" >Interprocess Communications</A>

<LI>

<A HREF="#E68E419" >Summary</A></UL></UL></UL>

<HR ALIGN=CENTER>

<A NAME="E66E54"></A>

<H1 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>54</B></FONT></CENTER></H1>

<BR>

<A NAME="E67E54"></A>

<H2 ALIGN=CENTER>

<CENTER>

<FONT SIZE=6 COLOR="#FF0000"><B>Network Programming</B></FONT></CENTER></H2>

<BR>

<P>This chapter will look at the basic concepts you need for network programming:

<BR>

<UL>

<LI>Ports and sockets

<BR>

<BR>

<LI>Record and file locking

<BR>

<BR>

<LI>Interprocess communications

<BR>

<BR>

</UL>

<P>It is impossible to tell you how to program applications for a network in just a few pages. Indeed, the best reference to network programming available takes almost 800 pages in the first volume alone! If you really want to do network programming, you 
need a lot of experience with compilers, TCP/IP, network operating systems, and a great deal of patience.

<BR>

<P>For information on details of TCP/IP, check the book Teach Yourself TCP/IP in 14 Days by Tim Parker (Sams).

<BR>

<BR>

<A NAME="E68E415"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Ports and Sockets</B></FONT></CENTER></H3>

<BR>

<P>Network programming relies on the use of sockets to accept and transmit information. Although there is a lot of mystique about sockets, the concept is actually very simple to understand.

<BR>

<P>Most applications that use the two primary network protocols, Transmission Control Protocol (TCP) or User Datagram Protocol (UDP) have a port number that identifies the application. A port number is used for each different application the machine is 
handling, so it can keep track of them by numbers instead of names. The port number makes it easier for the operating system to know how many applications are using the system and which services are available.

<BR>

<P>In theory, port numbers can be assigned on individual machines by the system administrator, but some conventions have been adopted to allow better communications. This convention enables the port number to identify the type of service that one system is 
requesting from another. For this reason, most systems maintain a file of port numbers and their corresponding services.

<BR>

<P>Port numbers are assigned starting from the number 1. Normally, port numbers above 255 are reserved for the private use of the local machine, but numbers between 1 and 255 are used for processes requested by remote applications or for networking 
services.

<BR>

<P>Each network communications circuit that goes into and out of the host computer's TCP application layer is uniquely identified by a combination of two numbers, together called the socket. The socket is composed of the IP address of the machine and the 
port number used by the TCP software.

<BR>

<P>Because there are at least two machines involved in network communications, there will be a socket on both the sending and receiving machine. The IP address of each machine is unique, and the port numbers are unique to each machine, so socket numbers 
will also be unique across the network. This enables an application to talk to another application across the network based entirely on the socket number.

<BR>

<P>The sending and receiving machines maintain a port table that lists all active port numbers. The two machines involved have reversed entries for each session between the two, a process called binding. In other words, if one machine has the source port 
number 23 and the destination port number set at 25, then the other machine will have its source port number set at 25 and the destination port number set at 23.

<BR>

<BR>

<A NAME="E68E416"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Socket Programming</B></FONT></CENTER></H3>

<BR>

<P>Linux supports BSD style socket programming. Both connection-oriented and connectionless types of sockets are supported. In connection-oriented communication, the server and client establish a connection before any data is exchanged. In connectionless 
communication, data is exchanged as part of a message. In either case, the server always starts up first, binds itself to a socket, and listens to messages. How the server attempts to listen depends on the type of connection for which you have programmed 
it.

<BR>

<P>You need to know about only a few system calls:

<BR>

<UL>

<LI>socket()

<BR>

<BR>

<LI>bind()

<BR>

<BR>

<LI>accept()

<BR>

<BR>

<LI>listen()

<BR>

<BR>

<LI>connect()

<BR>

<BR>

<LI>sendto()

<BR>

<BR>

<LI>recvfrom()

<BR>

<BR>

</UL>

<P>We will cover these in the following examples.

<BR>

<BR>

<A NAME="E69E535"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>socket()</B></FONT></CENTER></H4>

<BR>

<P>The socket() system call creates a socket for the client or the server. The socket function is defined as follows:

<BR>

<PRE>

<FONT COLOR="#000080">#include&lt;sys/types.h&gt;

#include&lt;sys/socket.h&gt;

int socket(int family, int type, int protocol)</FONT></PRE>

<P>For Linux, you will have family = AF_UNIX. The type is either SOCK_STREAM for reliable, though slower communications or SOCK_DGRAM for faster, but less reliable communications. The protocol should be IPPROTO_TCP for SOCK_STREAM and IPPROTO_UDP for 
SOCK_DGRAM.

<BR>

<P>The return value from this function is -1 if there was an error; otherwise, it's a socket descriptor. You will use this socket descriptor to refer to this socket in all subsequent calls in your program.

<BR>

<P>Sockets are created without a name. Clients use the name of the socket in order to read or write to it. This is where the bind function comes in.

<BR>

<BR>

<A NAME="E69E536"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>bind()</B><B> System Call</B></FONT></CENTER></H4>

<BR>

<P>The bind() system call assigns a name to an unnamed socket.

<BR>

<PRE>

<FONT COLOR="#000080">#include&lt;sys/types.h&gt;

#include&lt;sys/socket.h&gt;

int bind(int sockfd, struct sockaddr *saddr, int addrlen)</FONT></PRE>

<P>The first item is a socket descriptor. The second is a structure with the name to use, and the third item is the size of the structure.

<BR>

<P>Now that you have bound an address for your server or client, you can connect() to it or listen on it. If your program is a server, then it sets itself up to listen and accept connections. Let's look at the function available for such an endeavor.

<BR>

<BR>

<A NAME="E69E537"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>listen()</B><B> System Call</B></FONT></CENTER></H4>

<BR>

<P>The listen() system call is used by the server. It is defined as follows:

<BR>

<PRE>

<FONT COLOR="#000080">#include&lt;sys/types.h&gt;

#include&lt;sys/socket.h&gt;

int listen(int sockfd, int backlog);</FONT></PRE>

<P>The sockfd is the descriptor of the socket. The backlog is the number of waiting connections at one time before rejecting any. Use the standard value of 5 for backlog. A returned value of less than 1 indicates an error.

<BR>

<P>If this call is successful, you can accept connections.

<BR>

<BR>

<A NAME="E69E538"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>accept()</B><B> System Call</B></FONT></CENTER></H4>

<BR>

<P>The accept() system call is used by a server to accept any incoming messages from clients' connect() calls. Be aware that this function will not return if no connections are received.

<BR>

<PRE>

<FONT COLOR="#000080">#include&lt;sys/types.h&gt;

#include&lt;sys/socket.h&gt;

int accept(int sockfd, struct sockaddr *peeraddr, int addrlen)</FONT></PRE>

<P>The parameters are the same as that for the bind call, with the exception that the peeraddr points to information about the client that is making a connection request. Based on the incoming message, the fields in the structure pointed at by peeraddr are 
filled out.

<BR>

<P>So how does a client connect to a server. Let's look at the connect() call.

<BR>

<BR>

<A NAME="E69E539"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>The </B><B>connect()</B><B> System Call</B></FONT></CENTER></H4>

<BR>

<P>The connect() system call is used by clients to connect to a server in a connection-oriented system. This connect() call should be made after the bind() call.

<BR>

<PRE>

<FONT COLOR="#000080">#include&lt;sys/types.h&gt;

#include&lt;sys/socket.h&gt;

int connect(int sockfd, struct sockaddr *servsaddr, int addrlen)</FONT></PRE>

<P>The parameters are the same as that for the bind call, with the exception that the servsaddr points to information about the server that the client is connecting to. The accept call creates a new socket for the server to work with the request. This way 
the server can fork() off a new process and wait for more connections. On the server side of things, you would have code that looks like that shown in Listing 54.1.

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 54.1. Server side for socket-oriented protocol.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">#include &lt;sys/types.h&gt;

#include &lt;sys/socket.h&gt;

#include &lt;linux/in.h&gt;

#include &lt;linux/net.h&gt;

#define MY_PORT 6545

main(int argc, char *argv[])

{

int sockfd, newfd;

int cpid; /* child id */

struct sockaddr_in servaddr;

struct sockaddr_in clientInfo;

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0) &lt; 0)

{

myabort(&quot;Unable to create socket&quot;);

}

bzero((char *)&amp;servaddr, sizeof(servaddr));

servaddr.sin_family = AF_INET;

servaddr.sin_addr.s_addr = htonl(INADDR_ANY);

servaddr.sin_family = htons(MY_PORT);

/*

* The htonl(for a long integer) and htons(for short integer) convert

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美国产日韩亚洲一区| 亚洲制服丝袜av| 91蜜桃传媒精品久久久一区二区| 日本欧洲一区二区| 亚洲一卡二卡三卡四卡无卡久久| 裸体歌舞表演一区二区| 午夜精品久久久久久久久| 亚洲你懂的在线视频| 国产精品视频你懂的| 亚洲国产岛国毛片在线| 日本中文字幕一区二区有限公司| 国产大陆精品国产| 99re热这里只有精品免费视频| 国产精品一区免费在线观看| youjizz久久| 91久久精品日日躁夜夜躁欧美| 日本精品裸体写真集在线观看 | 国产精品女人毛片| 美女一区二区在线观看| 国产精品一区二区久激情瑜伽| 欧美精品自拍偷拍动漫精品| 7878成人国产在线观看| 日韩一区二区在线观看视频 | 婷婷久久综合九色国产成人| 99re亚洲国产精品| 中文字幕一区三区| 午夜电影一区二区| 欧美日韩国产小视频| 国产三级精品三级| 亚洲国产三级在线| 国产大陆a不卡| 国产农村妇女毛片精品久久麻豆 | 亚洲欧美激情一区二区| av不卡一区二区三区| 亚洲日本欧美天堂| 亚洲成人手机在线| 国产99精品在线观看| 色综合亚洲欧洲| 精品入口麻豆88视频| 国产精品三级在线观看| 成人性生交大片免费看在线播放| 欧美日韩一区二区电影| 久久久九九九九| 亚洲国产欧美在线| 欧美日韩国产成人在线免费| 亚洲成年人影院| 精品捆绑美女sm三区| 国产成人在线色| 亚洲精品欧美在线| 成人免费av资源| 亚洲男女一区二区三区| 欧美日韩免费观看一区三区| 全国精品久久少妇| 欧美日韩视频专区在线播放| 日韩国产精品久久久久久亚洲| 久久综合给合久久狠狠狠97色69| 亚洲成人免费电影| 欧美一区二区三区免费| 天天综合天天综合色| 久久综合久久99| 99久久99精品久久久久久| 午夜不卡av免费| 久久久国产精品午夜一区ai换脸| 色婷婷av一区二区三区软件| 1区2区3区精品视频| 欧美视频中文一区二区三区在线观看| 中文字幕一区二区三区色视频| 91国模大尺度私拍在线视频| 蜜臀久久99精品久久久久宅男| 国产视频视频一区| 国产99久久久精品| 午夜国产不卡在线观看视频| 中文欧美字幕免费| 欧美日韩视频专区在线播放| 高清免费成人av| 日韩精品一二三区| 日韩一卡二卡三卡| 色综合久久综合| 狠狠色狠狠色综合系列| 精品国产123| 国产一区二区三区日韩| 久久久久99精品国产片| 欧美久久一区二区| 99精品久久99久久久久| 国产精品一区一区| 免费观看91视频大全| 一区二区三区美女视频| 欧美欧美欧美欧美| 91麻豆产精品久久久久久 | 亚洲黄网站在线观看| 久久久99精品免费观看| 欧美一区二区三区的| 欧洲一区在线观看| 蜜桃av一区二区三区电影| 一区二区三区四区不卡在线 | 欧美日韩成人一区| 91日韩在线专区| 福利视频网站一区二区三区| 美女一区二区视频| 日产国产高清一区二区三区| 亚洲3atv精品一区二区三区| 亚洲色图在线看| 国产精品国产三级国产普通话三级| 99综合影院在线| 国产成人精品亚洲777人妖 | 91九色最新地址| 91蜜桃视频在线| 色网综合在线观看| 一本久久精品一区二区| 91丨国产丨九色丨pron| 国产成人免费视频网站高清观看视频| 久久精品99国产精品日本| 日本不卡视频在线观看| 水蜜桃久久夜色精品一区的特点| 一级特黄大欧美久久久| 亚洲国产一区二区视频| 亚洲国产欧美另类丝袜| 日韩成人午夜电影| 日韩经典一区二区| 日韩电影免费在线| 激情欧美一区二区| 国产米奇在线777精品观看| 国产久卡久卡久卡久卡视频精品| 国产毛片精品国产一区二区三区| 激情成人综合网| 国产不卡高清在线观看视频| 大陆成人av片| 色欲综合视频天天天| 欧美色精品天天在线观看视频| 欧美中文字幕一区| 日韩欧美在线1卡| 久久久五月婷婷| 国产精品久久毛片| 亚洲成人免费观看| 国产最新精品精品你懂的| 国产成人亚洲综合a∨婷婷图片| 成人免费看的视频| 91成人在线观看喷潮| 欧美一区二区三区婷婷月色| 久久一夜天堂av一区二区三区 | 爽好多水快深点欧美视频| 老司机精品视频线观看86| 成人中文字幕电影| 在线免费观看不卡av| 精品播放一区二区| 亚洲三级在线播放| 日日夜夜精品视频免费| 国产mv日韩mv欧美| 欧美日韩国产小视频| 久久精品视频免费| 亚洲一区二区在线观看视频 | 国产精品每日更新在线播放网址 | 欧美性videosxxxxx| 欧美v国产在线一区二区三区| 欧美高清在线精品一区| 视频一区国产视频| 99久久99久久精品国产片果冻| 在线不卡免费av| 中文字幕制服丝袜成人av | 婷婷中文字幕综合| 高清av一区二区| 日韩免费观看高清完整版在线观看| 欧美日韩视频在线第一区| 久久久久久久一区| 爽爽淫人综合网网站| 97精品国产露脸对白| 日韩一区二区三区视频在线观看 | 欧美午夜片在线观看| 欧美国产一区视频在线观看| 五月天激情综合网| av不卡免费电影| 国产日韩欧美精品在线| 日本麻豆一区二区三区视频| 99re免费视频精品全部| 久久久精品日韩欧美| 毛片av一区二区三区| 欧美丝袜丝交足nylons图片| 中文文精品字幕一区二区| 久久电影网站中文字幕| 欧美日韩国产高清一区| 一区二区三区欧美日韩| 成人精品视频一区| 久久色成人在线| 久久国产人妖系列| 91精品午夜视频| 亚洲成人在线网站| 欧美中文字幕一区| 一区二区视频免费在线观看| 91在线免费播放| 国产精品日韩成人| 国产成人av一区| 国产午夜精品福利| 国产成人亚洲综合a∨婷婷图片| 精品福利视频一区二区三区| 青青草97国产精品免费观看| 欧美久久久久久久久久 | 亚洲欧美日韩久久精品| 成人黄色小视频在线观看| 欧美日韩一级片在线观看| 亚洲激情一二三区|