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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? rhl54.htm

?? linux的初學(xué)電子書(shū)
?? HTM
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
* a host oriented byte order * into a network order.

*/

if (bind(sockfd,(struct sockaddr *)&servaddr,sizeof(struct sockaddr)) < 0)

{

myabort("Unable to bind socket");

}

listen(sockfd,5);

for (;;)

{

/* wait here */

newfd=accept(sockfd,(struct sockaddr *)&clientInfo,

sizeof(struct sockaddr);

if (newfd < 0)

{

myabort("Unable to accept on socket");

}

if ((cpid = fork()) < 0)

{

myabort("Unable to fork on accept");

}

else if (cpid == 0) { /* child */

close(sockfd); /* no need for original */

do_your_thing(newfd);

exit(0);

}

close(newfd); /* in the parent */

}

}</FONT></PRE>

<P>In the case of connection-oriented protocols, the server performs the following functions:

<BR>

<UL>

<LI>Creates a socket with a call to the socket() function.

<BR>

<BR>

<LI>Binds itself to an address with the bind() function call.

<BR>

<BR>

<LI>Listens for connections with the listen() function call.

<BR>

<BR>

<LI>Accepts any incoming requests with the accept() function call.

<BR>

<BR>

<LI>Gets incoming messages with the read() function and replies back with the write() call.

<BR>

<BR>

</UL>

<P>Now let's look at the client side of things in Listing 54.2.

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 54.2. Client side function.</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

#define MY_HOST_ADDR &quot;204.25.13.1&quot;

int getServerSocketId()

{

int fd, len;

struct sockaddr_in unix_addr;

/* create a Unix domain stream socket */

if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) &lt; 0)

{

return(-1);

}

/* fill socket address structure w/our address */

memset(&amp;unix_addr, 0, sizeof(unix_addr));

unix_addr.sin_family = AF_INET;

/* convert internet address to binary value*/

unix_addr.sin_addr.s_addr = inet_addr(MY_HOST_ADDR);

unix_addr.sin_family = htons(MY_PORT);

if (bind(fd, (struct sockaddr *) &amp;unix_addr, len) &lt; 0)

return(-2);

memset(&amp;unix_addr, 0, sizeof(unix_addr));

if (connect(fd, (struct sockaddr *) &amp;unix_addr, len) &lt; 0)

return(-3);

return(fd);

}</FONT></PRE>

<P>The client for connection-oriented communication also takes the following steps:

<BR>

<UL>

<LI>Creates a socket with a call to the socket() function.

<BR>

<BR>

<LI>Attempts to connect to the server with a connect() call.

<BR>

<BR>

<LI>If a connection is made, requests for data with the write() call, and reads incoming replies with the read() function.

<BR>

<BR>

</UL>

<BR>

<A NAME="E69E540"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Connectionless Socket Programming</B></FONT></CENTER></H4>

<BR>

<P>Now let's consider the case of a connectionless exchange of information. The principle on the server side is different from the connection-oriented server side in that the server calls recvfrom() instead of the listen and accept calls. Also, to reply to 
messages, the server uses the sendto() function call. See Listing 54.3 for the server side.

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 54.3. The server side.</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

#define MAXM 4096

char mesg[MAXM];

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

* a host oriented byte order * into a network order.

*/

if (bind(sockfd,(struct sockaddr *)&amp;servaddr,sizeof(struct sockaddr)) &lt; 0)

{

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

}

for (;;)

{

/* wait here */

n = recvfrom(sockfd, mesg, MAXM, 0,

(struct sockaddr *)&amp;clientInfo,

sizeof(struct sockaddr));

doSomethingToIt(mesg);

sendto(sockfd,mesg,n,0,

(struct sockaddr *)&amp;clientInfo,

sizeof(struct sockaddr));

}

}</FONT></PRE>

<P>As you can see, the two function calls to process each message make this an easier implementation than a connection-oriented one. However, you have to process each message one at a time because messages from multiple clients can be multiplexed together. 
In a connection-oriented scheme, the child process always knows where each message originated.

<BR>

<P>The client does not have to call the connect() system call either. Instead, the client can call the sendto() function directly. The client side is identical to the server side, with the exception that the sendto call is made before the recvfrom() call.

<BR>

<PRE>

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

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

int sendto((int sockfd,

const void *message__, /* the pointer to message */

int length, /* of message */

unsigned int type, /* of routing, leave 0 *

const struct sockaddr * client, /* where to send it */

int length ); /* of sockaddr);</FONT></PRE>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>If you are a BSD user, use the sendto() call, do not use sendmsg() call. The sendto() call is more efficient.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<P>Any errors are indicated by a return value of -1. Only local errors are detected.

<BR>

<P>The recvfrom() system call is defined as follows:

<BR>

<PRE>

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

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

int recvfrom(int sockfd,

const void *message__, /* the pointer to message */

int length, /* of message */

unsigned int flags, /* of routing, leave 0 *

const struct sockaddr * client, /* where to send it */

int length ); /* of sockaddr);</FONT></PRE>

<P>If a message is too long to fit in the supplied buffer, the extra bytes are discarded. The call may return immediately or wait forever, depending on the type of the flag being set. You can even set time out values. Check the man pages for recvfrom for 
more information.

<BR>

<P>There you have it: the very basics of how to program applications to take advantage of the networking capabilities under Linux. We have not even scratched the surface of all the intricacies of programming for networks. A good starting point for more 
detailed information would be UNIX Network Programming by W. Richard Stevens, published in 1990 by Prentice Hall. This book is a classic used in universities and is, by far, the most detailed book to date.

<BR>

<BR>

<A NAME="E68E417"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Record and File Locking</B></FONT></CENTER></H3>

<BR>

<P>When two processes want to share a file, the danger exists that one process might affect the contents of the file, and thereby affect the other process. For this reason, most operating systems use a mutually exclusive principle: When one process has a 
file open, no other process can touch it. This is called file locking.

<BR>

<P>The technique is simple to implement. What usually happens is that a &quot;lock file&quot; is created with the same name as the original file but with the extension .lock, which tells other processes that the file is unavailable. This is how many Linux 
spoolers, such as the print system and UUCP, implement file locking. It is a brute-force method, perhaps, but effective and easy to program.

<BR>

<P>Unfortunately, this technique is not good when you must have several processes access the same information quickly because the delays waiting for file opening and closing can grow to be appreciable. Also, if one process doesn't release the file 
properly, other processes can hang there, waiting for access.

<BR>

<P>For this reason, record locking is sometimes implemented. With record locking, a single part of a larger file is locked to prevent two processes from changing its contents at the same time. Record locking enables many processes to access the same file 
at the same time, each updating different records within the file, if necessary. The programming necessary to implement record locking is more complex than file locking, of course.

<BR>

<P>Normally, to implement record locking, you use a file offset, or the number of characters from the beginning of the file. In most cases, a range of characters are locked, so the program has to note the start of the locking region and the length of it, 
and then store that information somewhere other processes can examine it.

<BR>

<P>Writing either file locking or record locking code requires a good understanding of the operating system, but is otherwise not difficult, especially because there are thousands of programs readily available from the Internet, in networking programming 
books, and on BBSes to examine for example code.

<BR>

<BR>

<A NAME="E68E418"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Interprocess Communications</B></FONT></CENTER></H3>

<BR>

<P>Network programming always involves two or more processes talking to each other (interprocess communications), so the way in which processes communicate is vitally important to network programmers. Network programming differs from the usual method of 
programming in a few important aspects. A traditional program can talk to different modules (or even other applications on the same machine) through global variables and function calls. That doesn't work across networks.

<BR>

<P>A key goal of network programming is to ensure that processes don't interfere with each other. Otherwise, systems can get bogged down or lock up. Therefore, processes must have a clean and efficient method of communicating. UNIX is particularly strong 
in this regard, because many of the basic UNIX capabilities, such as pipes and queues, are used effectively across networks.

<BR>

<P>Writing code for interprocess communications is quite difficult compared to single application coding. If you want to write this type of routine, you should study sample programs from a network programming book or a BBS site to see how they accomplish 
the task.

<BR>

<BR>

<A NAME="E68E419"></A>

<H3 ALIGN=CENTER>

<CENTER>

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

<BR>

<P>Few people need to write network applications, so the details of the process are best left to those who want them. Experience and lots of examples are the best way to begin writing network code, and mastering the skills can take many years.

<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="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></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>


</BODY></HTML>



?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一级久久久| 亚洲123区在线观看| 精品粉嫩aⅴ一区二区三区四区| 欧美美女一区二区在线观看| 欧美日韩中文精品| 欧美日韩国产小视频| 欧美喷水一区二区| 欧美福利视频一区| 欧美精品一区二区三区蜜桃 | 久久综合色播五月| 精品电影一区二区| 久久无码av三级| 国产精品天美传媒沈樵| 1024成人网色www| 一区二区三区91| 日韩中文字幕亚洲一区二区va在线| 亚洲电影在线播放| 蜜臀av性久久久久蜜臀aⅴ四虎| 九色综合国产一区二区三区| 国产乱码一区二区三区| 99久久精品免费| 欧美性色黄大片| 日韩一区二区不卡| 国产欧美视频在线观看| 亚洲欧美日韩小说| 午夜日韩在线观看| 国内精品久久久久影院薰衣草| 国产精品综合网| 91免费视频网址| 884aa四虎影成人精品一区| 精品国产乱码久久久久久牛牛| 国产欧美视频一区二区| 亚洲综合激情网| 国产一区激情在线| 91影视在线播放| 91精品久久久久久蜜臀| 国产三级一区二区三区| 亚洲精品午夜久久久| 麻豆视频观看网址久久| av不卡在线播放| 51精品久久久久久久蜜臀| 久久亚洲春色中文字幕久久久| 欧美日韩国产大片| 国产亚洲欧美日韩俺去了| 亚洲天堂福利av| 蜜桃精品在线观看| 色综合天天综合色综合av| 欧美卡1卡2卡| 国产精品色噜噜| 日韩精品福利网| 国产成人久久精品77777最新版本| 色偷偷久久人人79超碰人人澡 | 欧美sm美女调教| 日韩一区中文字幕| 美女视频网站黄色亚洲| 91一区二区在线观看| 精品国产免费久久| 亚洲综合精品自拍| 成人免费av网站| 日韩美女视频一区二区在线观看| 欧美日韩极品在线观看一区| 老司机午夜精品| 99久久精品国产观看| 91精品国产黑色紧身裤美女| 亚洲欧洲精品天堂一级| 免费av成人在线| 在线一区二区视频| 国产欧美一区视频| 免费成人在线影院| 欧美影院午夜播放| 亚洲天堂福利av| 懂色av中文一区二区三区| 日韩欧美一区二区在线视频| 亚洲综合男人的天堂| www.久久久久久久久| 精品久久国产字幕高潮| 亚洲电影第三页| 一本色道亚洲精品aⅴ| 日本一区二区视频在线观看| 久久精品72免费观看| 欧美日韩五月天| 伊人色综合久久天天人手人婷| 国产盗摄一区二区| 精品乱人伦小说| 久99久精品视频免费观看| 717成人午夜免费福利电影| 亚洲精品国产品国语在线app| 国产成人免费xxxxxxxx| 日韩欧美一区二区久久婷婷| 日韩av不卡在线观看| 欧美日韩综合一区| 亚洲人成人一区二区在线观看 | 在线影视一区二区三区| 亚洲欧洲日韩综合一区二区| 成人性生交大片免费看中文| 久久久噜噜噜久久人人看 | 国产乱国产乱300精品| 日韩精品一区二区三区视频在线观看 | 精品人在线二区三区| 久久99精品国产.久久久久久| 一区二区三区高清| 白白色 亚洲乱淫| 国产亚洲精品aa午夜观看| 国内偷窥港台综合视频在线播放| 精品少妇一区二区三区视频免付费| 亚洲成人av一区二区三区| 欧美午夜电影在线播放| 亚洲一区二区美女| 欧美妇女性影城| 久久精品国产99国产| 久久婷婷久久一区二区三区| 黄页网站大全一区二区| 久久久久免费观看| 成人一级黄色片| 亚洲天堂av一区| 欧美日韩一区二区三区四区| 午夜电影久久久| 欧美成人激情免费网| 国产资源精品在线观看| 国产精品网站在线| 一本色道a无线码一区v| 日日夜夜精品视频天天综合网| 日韩欧美中文字幕公布| 国产精品一区二区你懂的| 国产精品久久久久久亚洲毛片| www.欧美.com| 午夜视频在线观看一区二区| 婷婷丁香久久五月婷婷| 欧美日韩一级视频| 日本人妖一区二区| 久久综合成人精品亚洲另类欧美 | 久久超碰97中文字幕| 久久久久久亚洲综合影院红桃| 国产精品小仙女| 一区二区三区不卡在线观看| 欧美一级在线免费| 国产成人免费xxxxxxxx| 亚洲午夜av在线| 久久人人超碰精品| 色婷婷狠狠综合| 美女爽到高潮91| 亚洲三级理论片| 91精品国产综合久久久久久漫画| 国产麻豆视频一区二区| 一区二区三区在线观看网站| 欧美一区二区国产| 成人精品在线视频观看| 午夜视频在线观看一区二区三区| 久久先锋影音av鲁色资源网| 在线观看网站黄不卡| 国产在线一区观看| 亚洲激情网站免费观看| 26uuu国产在线精品一区二区| 色综合久久综合网97色综合| 九色|91porny| 一区二区三区.www| 久久久777精品电影网影网| 蜜桃久久久久久| 不卡的av在线播放| 亚洲电影一区二区三区| 久久久久久99精品| 91精品一区二区三区在线观看| 成人免费视频国产在线观看| 日韩国产一二三区| 亚洲丝袜精品丝袜在线| 精品av久久707| 欧美日韩国产一级片| www.欧美亚洲| 国产剧情av麻豆香蕉精品| 性做久久久久久免费观看| 国产精品久久久久久福利一牛影视| 制服丝袜中文字幕一区| 色爱区综合激月婷婷| 床上的激情91.| 国产曰批免费观看久久久| 婷婷丁香久久五月婷婷| 亚洲精品一卡二卡| 中文欧美字幕免费| 26uuu国产电影一区二区| 欧美电影一区二区| 在线欧美日韩精品| 99久久综合狠狠综合久久| 黑人精品欧美一区二区蜜桃| 日韩电影在线看| 亚洲成人av在线电影| 一区二区三区在线免费视频| 国产精品久久午夜| 欧美极品xxx| 久久综合狠狠综合久久激情| 日韩免费视频一区二区| 777xxx欧美| 欧美日本韩国一区| 欧美日韩国产精选| 欧美午夜精品一区二区三区| 91麻豆国产香蕉久久精品| 成人成人成人在线视频| 成人永久免费视频| 丰满亚洲少妇av| 成人爽a毛片一区二区免费| 国产成人免费视|