⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codeexm2.htm

📁 《计算机网络与因特网》(原书第4版) 作者:Douglas Comer博士 出版社:机械工业出版社 书中例子的代码
💻 HTM
字号:
<HTML><HEAD><TITLE>NETBOOK - Code Sample EXM2</TITLE></HEAD><BODY BGCOLOR="#FFFFFF"><P><TABLE BORDER="0" CELLPADDING="5" CELLSPACING="0" WIDTH="600"><TR>  <TD WIDTH="112" VALIGN="TOP" BGCOLOR="#759AC4" CELLPADDING="0"><img src="../pgmatrls/sidebar.gif" width="112" height="410" usemap="#sidebar" ismap alt="" border="0" ><map name="sidebar"><area shape="rect" coords="0,325,100,364"  href="../othrpags/page22.htm" ><area shape="rect" coords="0,287,100,326"  href="../othrpags/page17.htm" ><area shape="rect" coords="0,248,100,287"  href="../othrpags/page18.htm" ><area shape="rect" coords="0,364,100,404"  href="../othrpags/code.htm" ><area shape="rect" coords="0,210,100,248"  href="../othrpags/page15.htm" ><area shape="rect" coords="0,170,100,210"  href="../othrpags/page03.htm" ><area shape="rect" coords="0,132,100,170"  href="../othrpags/page10.htm" ><area shape="rect" coords="0,93,100,132"   href="../index.htm" ><AREA SHAPE="DEFAULT" NOHREF></map>  </TD><TD WIDTH="420" VALIGN="TOP" BGCOLOR="#FFFFFF"><CENTER><H1>Code Sample EXM2</H1></CENTER><PRE>/* chatserver.c */#include &lt;stdlib.h&gt;#include &lt;stdio.h&gt;#include &lt;cnaiapi.h&gt;#define BUFFSIZE		256#define INPUT_PROMPT		"Input   &gt; "#define RECEIVED_PROMPT		"Received&gt; "int recvln(connection, char *, int);int readln(char *, int);/*----------------------------------------------------------------------- * * Program: chatserver * Purpose: wait for a connection from a chatclient & allow users to chat * Usage:   chatserver &lt;appnum&gt; * *----------------------------------------------------------------------- */intmain(int argc, char *argv[]){	connection	conn;	int		len;	char		buff[BUFFSIZE];	if (argc != 2) {		(void) fprintf(stderr, "usage: %s &lt;appnum&gt;\n", argv[0]);		exit(1);	}	(void) printf("Chat Server Waiting For Connection.\n");	/* wait for a connection from a chatclient */	conn = await_contact((appnum) atoi(argv[1]));	if (conn &lt; 0)		exit(1);		(void) printf("Chat Connection Established.\n");		/* iterate, reading from the client and the local user */	while((len = recvln(conn, buff, BUFFSIZE)) &gt; 0) {		(void) printf(RECEIVED_PROMPT);		(void) fflush(stdout);		(void) write(STDOUT_FILENO, buff, len);				/* send a line to the chatclient */		(void) printf(INPUT_PROMPT);		(void) fflush(stdout);		if ((len = readln(buff, BUFFSIZE)) &lt; 1)			break;		buff[len - 1] = '\n';		(void) send(conn, buff, len, 0);	}	/* iteration ends when EOF found on stdin or chat connection */	(void) send_eof(conn);	(void) printf("\nChat Connection Closed.\n\n");	return 0;}</PRE><p><p><p><HR WIDTH=89%  ALIGN=CENTER SIZE=2><center><h2>Item information</h2></center><p><TABLE CELLSPACING="0"><TD ALIGN="LEFT" VALIGN="TOP">Caption:</TD><TD ALIGN="LEFT"></TD><TR><TD ALIGN="LEFT">Code sample:</TD><TD ALIGN="LEFT">EXM2</td><tr><TD ALIGN="LEFT">Type:</TD><TD ALIGN="LEFT">code sample</TD><TR><TD ALIGN="LEFT">Item:</TD><TD ALIGN="LEFT"><A HREF="./codeEXM2.txt">Code sample EXM2</A> without caption</TD><TR><TD ALIGN="LEFT">Keywords:</TD><TD ALIGN="LEFT">network API</TR></TABLE></tr></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -