第三章 Windows Sockets 1

Size: px
Start display at page:

Download "第三章 Windows Sockets 1"

Transcription

1 第三章 Windows Sockets 1.1 应用实例 在本章中, 作者的实际工作为背景, 给出了一个使用 Windows Sockets 1.1 编程的具体例子 并对这个例子作了详细的分析 这个例子在 Windows 3.1 Windows Sockets 1.1 和 BSD OS for PC 2.0(BSD UNIX 微机版 ) 环境下调试通过 3.1 套接口网络编程原理 套接口有三种类型 : 流式套接口, 数据报套接口及原始套接口. 流式套接口定义了一种可靠的面向连接的服务, 实现了无差错无重复的顺序数据传输. 数据报套接口定义了一种无连接的服务, 数据通过相互独立的报文进行传输, 是无序的, 并且不保证可靠, 无差错. 原始套接口允许对低层协议如 IP 或 ICMP 直接访问, 主要用于新的网络协议实现的测试等. 无连接服务器一般都是面向事务处理的, 一个请求一个应答就完成了客户程序与服务程序之间的相互作用 若使用无连接的套接口编程, 程序的流程可以用图 3-1 表示

2 服务器 socket( ) 客户机 socket( ) bind( ) readfrom ( ) bind( ) 阻塞, 等待客户数据 处理服务请求 sendto( ) 服务请求 服务应答 sendto( ) readfrom ( ) close( ) close( ) 图 3-1 无连接套接口应用程序时序图 面向连接服务器处理的请求往往比较复杂, 不是一来一去的请求应答所能解决的, 而且往往是并发服务器 使用面向连接的套接口编程, 可以通过图 3-1 来表示 : 其时序

3 服务器 socket( ) bind( ) listen( ) accept( ) 客户机 socket( ) 阻塞, 等待客户数据 read( ) 处理服务请求 write( ) 建立连接 请求数据 应答数据 connect( ) w rite( ) read( ) close( ) close( ) 图 3-2 面向连接套接口应用程序时序图 套接口工作过程如下 : 服务器首先启动, 通过调用 socket() 建立一个套接口, 然后调用 bind() 将该套接口和本地网络地址联系在一起, 再调用 listen() 使套接口做好侦听的准备, 并规定它的请求队列的长度, 之后就调用 accept() 来接收连接. 客户在建立套接口后就可调用 connect() 和服务器建立连接. 连接一旦建立, 客户机和服务器之间就可以通过调用 read() 和 write() 来发送和接收数据. 最后, 待数据传送结束后, 双方调用 close() 关闭套接口. 3.2 Windows Sockets 编程原理 由于 Windows 的基于消息的特点,WINSOCK 和 BSD 套接口相比, 有如下一些新的扩充 : 1. 异步选择机制异步选择函数 WSAAsyncSelect() 允许应用程序提名一个或多个感兴趣的网络事件, 如

4 FD_READ,FD_WRITE,FD_CONNECT,FD_ACCEPT 等等代表的网络事件. 当被提名的网络事件发生时,Windows 应用程序的窗口函数将收到一个消息. 这样就可以实现事件驱动了. 2. 异步请求函数异步请求函数允许应用程序用异步方式获得请求的信息, 如 WSAAsyncGetXByY() 类函数. 这些函数是对 BSD 标准函数的扩充. 函数 WSACancelAsyncRequest() 允许用户中止一个正在执行的异步请求. 3. 阻塞处理方法 WINSOCK 提供了 " 钩子函数 " 负责处理 Windows 消息, 使 Windows 的消息循环能够继续.WINSOCK 提供了两个函数 (WSASetBlockingHook() 和 WSAUnhookBlockingHook()) 让应用程序设置或取消自己的 " 钩子函数 ". 函数 WSAIsBlocking() 可以检测是否阻塞, 函数 WSACancelBlockingCall() 可以取消一个阻塞的调用. 4. 错误处理 WINSOCK 提供了两个 WSAGetLastError() 和 WSASetLastError() 来获取和设置最近错误号. 5. 启动和终止由于 Windows Sockets 的服务是以动态连接库 WINSOCK.DLL 形式实现的, 所以必须要先调用 WSAStartup() 函数对 Windows Sockets DLL 进行初始化, 协商 WINSOCK 的版本支持, 并分配必要的资源. 在应用程序关闭套接口后, 还应调用 WSACleanup() 终止对 Windows Sockets DLL 的使用, 并释放资源, 以备下一次使用. 在这些函数中, 实现 Windows 网络实时通信的关键是异步选择函数 WSAAsyncSelect() 的使用. 用法及详细说明参见第 Windows Sockets 与 UNIX 套接口编程实例 下面是一个简单的基于连接的点对点实时通信程序. 它由两部分组成, 服务器在主机 UNIX 下直接运行, 客户机在 Windows 下运行 SERVER 介绍 由于 SERVER 是在 UNIX 下运行的, 它对套接口的使用都是 BSD 的标准函数, 程序也比较简单, 只有一段程序, 下面简要解释一下. 首先, 建立自己的套接口. 在互连网的进程通信中, 全局标识一个进程需要一个被称为 " 半相关 " 的三元组 ( 协议, 本地主机地址, 本地端口号 ) 来描述, 而一个完整的进程通信实例则需要一个被称为 " 相关 " 的五元组 ( 协议, 本地主机地址, 本地端口号, 远端主机地址, 远端端口号 ) 来描述. s=socket(af_inet, SOCK_STREAM, 0) 该函数建立指定地址格式, 数据类型和协议下的套接口, 地址格式为 AF_INET( 唯一支持的格式 ), 数据类型 SOCK_STREAM 表示建立流式套接口, 参数三为 0, 即协议缺省. bind(s, (struct sockaddr *)&server, sizeof(server)) 该函数将建立服务器本地的半相关, 其中,server 是 sockaddr_in 结构, 其成员描述了本地端口号和本地主机地址, 经过 bind() 将服务器进程在网上标识出来. 然后, 建立连接. 先是调用 listen() 函数表示开始侦听. 再通过 accept() 调用等待接收连接. listen(s,1) 表示连接请求队列长度为 1, 即只允许有一个请求, 若有多个请求, 则出现错误, 给出错误代码 WSAECONNREFUSED. ns = accept(s, (struct sockaddr *)&client, &namelen)) accept() 阻塞 ( 缺省 ) 等待请求队列中的请求, 一旦有连接请求来, 该函数就建立一个和 s 有相

5 同属性的新的套接口.client 也是一个 sockaddr_in 结构, 连接建立时填入请求连接的套接口的半相关信息. 接下来, 就可以接收和发送数据了. recv(ns,buf,1024,0) send(ns,buf,pktlen,0) 上面两个函数分别负责接收和发送数据,recv 从 ns( 建立连接的套接口 ) 接收数据放入 buf 中,send 则将 buf 中数据发送给 ns. 至于第四个参数, 表示该函数调用方式, 可选择 MSG_DONTROUTE 和 MSG_OOB, 0 表示缺省. 最后, 关闭套接口. close(ns); close(s); CLIENT 介绍 客户端是在 Windows 上运行的, 使用了一些 Windows Sockets 的扩展函数, 稍微复杂一些. 包括了.RC 和.C 两个文件, 其中的主窗口函数 ClientProc() 是程序的主要部分, 下面简单解释一下. 首先, 是在 WinMain() 中建立好窗口后, 即向主窗口函数发一条自定义的 WM_USER 消息, 做相关的准备工作. 在主窗口函数中, 一接收到 WM_USER 消息, 首先调用 WSAStartup() 函数初始化 Windows Sockets DLL, 并检查版本号. 如下 : Status = WSAStartup(VersionReqd, lpmywsadata); 其中,VersionReqd 描述了 WINSOCK 的版本 ( 这里为 1.1 版 ),lpmywsadata 指向一个 WSADATA 结构, 该结构描述了 Windows Sockets 的实现细节. WSAStartup() 之后, 进程通过主机名 ( 运行时命令行参数传入 ) 获取主机地址, 如下 : hostaddr = gethostbyname(server_address); hostaddr 指向 hostent 结构, 内容参见 然后, 进程就不断地消息循环, 等待用户通过菜单选择 " 启动 ". 这时, 通过调用 Client() 来启动套接口. 在 Client() 中, 首先也是调用 socket() 来建立套接口. 如下 : if ((s = socket(af_inet, SOCK_STREAM, 0)) == INVALID_SOCKET) AlertUser(hWnd, "Socket Failed"); return (FALSE); 紧接着, 调用 WSAAsyncSelect() 函数提名 FD_CONNECT 网络事件, 如下 : if (!SetSelect(hWnd, FD_CONNECT)) return (FALSE); SetSelect() 主要就是调用 WSAASyncSelect(), 让 Windows Sockets DLL 在侦测到连接建立时, 就发送一条 UM_SOCK 的自定义消息, 使消息循环继续下去. 如下 : BOOL SetSelect(HWND hwnd, long levent) if (WSAAsyncSelect(s, hwnd, UM_SOCK, levent) == SOCKET_ERROR) AlertUser(hWnd, "WSAAsyncSelect Failure."); return (FALSE); return (TRUE); 为建立连接, 必须马上调用 connect() 如下, 由于先调用了 WSAASyncSelect(),connect() 便是非阻塞调用. 进程发出连接请求后就不管了, 当连接建立好后,WINSOCK DLL 自动发一条消息给

6 主窗口函数, 以使程序运行下去. connect(s, (struct sockaddr FAR *)&dst_addr, sizeof(dst_addr)); 窗口函数在收到 UM_SOCK 消息后, 判断是由哪个网络事件引起的, 第一次, 必然是由连接事件引起的, 这样, 就会执行相应的程序段, 同样调用 SetSelect() 来提名 FD_WRITE 事件. 希望在套接口可发送数据时接到消息. 在收到 FD_WRITE 消息时, 先调用 send() 发送数据, 再调用 SetSelect() 来提名 FD_READ 事件, 希望在套接口可接收数据是接到消息. 在收到 FD_READ 消息时, 先调用 recv() 来接收数据再提名 FD_WRITE 事件, 如此循环下去. 直到发生连接关闭的事件 FD_CLOSE, 这时就调用 WSAAsyncSelect(s,hWnd,0,0) 来停止异步选择. 在窗口函数接到 WM_DESTROY 消息时 ( 即关闭窗口之前 ), 先调用 closesocket()( 作用同 UNIX 中的 close()) 来关闭套接口, 再调用 WSACleanup() 终止 Windows Sockets DLL, 并释放资源 源程序清单 程序 1:CLIENT.RC ClientMenu MENU BEGIN POPUP "&Server" BEGIN MENUITEM "&Start...", 101 MENUITEM "&Exit", 102 END END 程序 2:CLIENT.C #define USERPORT #define IDM_START 101 #define IDM_EXIT 102 #define UM_SOCK WM_USER + 0X100 #include <alloc.h> #include <mem.h> #include <windows.h> #include <winsock.h> #define MAJOR_VERSION 1 #define MINOR_VERSION 2 #define WSA_MAKEWORD(x,y) ((y)*256+(x)) HANDLE hinst; char server_address[256] = 0; char buffer[1024]; char FAR * lpbuffer = &buffer[0]; SOCKET s = 0; struct sockaddr_in dst_addr; struct hostent far *hostaddr; struct hostent hostnm; struct servent far *sp; int count = 0; BOOL InitApplication(HINSTANCE hinstance); long FAR PASCAL ClientProc(HWND hwnd, unsigned message, UINT wparam, LONG lparam); void AlertUser(HWND hwnd, char *message);

7 BOOL Client(HWND hwnd); BOOL ReceivePacket(HWND hwnd); BOOL SetSelect(HWND hwnd, long levent); BOOL SendPacket(HWND hwnd, int len); int PASCAL WinMain(HANDLE hinstance, HANDLE hprevinstance, LPSTR lpcmdline, int ncmdshow) HWND hwnd; MSG msg; lstrcpy((lpstr)server_address, lpcmdline); if (!hprevinstance) if (!InitApplication(hInstance)) return (FALSE); hinst = hinstance; hwnd = CreateWindow("ClientClass", "Windows ECHO Client", WS_OVERLAPPEDWINDOW,\ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,\ hinstance, NULL); if (!hwnd) return (FALSE); ShowWindow(hWnd, ncmdshow); UpdateWindow(hWnd); PostMessage(hWnd, WM_USER, (WPARAM)0, (LPARAM)0); while (GetMessage(&msg, NULL, NULL, NULL)) TranslateMessage(&msg); DispatchMessage(&msg); return (msg.wparam); BOOL InitApplication(HINSTANCE hinstance) WNDCLASS WndClass; char *szappname = "ClientClass"; // fill in window class information WndClass.lpszClassName = (LPSTR)szAppName; WndClass.hInstance = hinstance; WndClass.lpfnWndProc = ClientProc; WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hIcon = LoadIcon(hInstance, NULL); WndClass.lpszMenuName = "ClientMenu"; WndClass.hbrBackground = GetStockObject(WHITE_BRUSH); WndClass.style = CS_HREDRAW CS_VREDRAW; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0;

8 // register the class if (!RegisterClass(&WndClass)) return(false); return(true); long FAR PASCAL ClientProc(HWND hwnd, unsigned message, UINT wparam, LONG lparam) int length, i; WSADATA wsadata; int Status; switch (message) case WM_USER: WORD wmajorversion, wminorversion; LPWSADATA lpmywsadata; WORD VersionReqd; int ret; wmajorversion = MAJOR_VERSION; wminorversion = MINOR_VERSION; VersionReqd = WSA_MAKEWORD(wMajorVersion,wMinorVersion); lpmywsadata = (LPWSADATA)malloc(sizeof(WSADATA)); Status = WSAStartup(VersionReqd, lpmywsadata); if (Status!= 0) AlertUser(hWnd, "WSAStartup() failed\n"); PostQuitMessage(0); hostaddr = gethostbyname(server_address); if (hostaddr == NULL) AlertUser(hWnd, "gethostbyname ERROR!\n"); WSACleanup(); PostQuitMessage(0); _fmemcpy(&hostnm, hostaddr, sizeof(struct hostent)); case WM_COMMAND: switch (wparam) case IDM_START: if (!Client(hWnd)) closesocket(s); AlertUser(hWnd, "Start Failed");

9 case IDM_EXIT: // WSACleanup(); PostQuitMessage(0); case UM_SOCK: switch (lparam) case FD_CONNECT: if (!SetSelect(hWnd, FD_WRITE)) closesocket(s); case FD_READ: if (!ReceivePacket(hWnd)) AlertUser(hWnd, "Receive Packet Failed.\n"); closesocket(s); if (!SetSelect(hWnd, FD_WRITE)) closesocket(s); case FD_WRITE: for (i = 0; i < 1024; i ++) buffer[i] = (char)'a' + i % 26; length = 1024; if (!SendPacket(hWnd, length)) AlertUser(hWnd, "Packet Send Failed!\n"); closesocket(s); if (!SetSelect(hWnd, FD_READ)) closesocket(s); case FD_CLOSE: if (WSAAsyncSelect(s, hwnd, 0, 0) == SOCKET_ERROR) AlertUser(hWnd, "WSAAsyncSelect Failed.\n"); default: if (WSAGETSELECTERROR(lParam)!= 0) AlertUser(hWnd, "Socket Report Failure."); closesocket(s); case WM_DESTROY:

10 closesocket(s); WSACleanup(); PostQuitMessage(0); default: return (DefWindowProc(hWnd, message, wparam, lparam)); return(null); void AlertUser(HWND hwnd, char *message) MessageBox(hWnd, (LPSTR)message, "Warning", MB_ICONEXCLAMATION); return; BOOL Client(HWND hwnd) memset(&dst_addr,'\0', sizeof (struct sockaddr_in)); _fmemcpy((char FAR *)&dst_addr.sin_addr,(char FAR *)hostnm.h_addr,hostnm.h_length); dst_addr.sin_family = hostnm.h_addrtype; dst_addr.sin_port = htons(userport); if ((s = socket(af_inet, SOCK_STREAM, 0)) == INVALID_SOCKET) AlertUser(hWnd, "Socket Failed"); return (FALSE); if (!SetSelect(hWnd, FD_CONNECT)) return (FALSE); connect(s, (struct sockaddr FAR *)&dst_addr, sizeof(dst_addr)); return (TRUE); BOOL ReceivePacket(HWND hwnd) HDC hdc; int length; int i1,i2,i3; char line1[255], line2[255], line3[255]; count ++; if ((length = recv(s, lpbuffer, 1024, 0)) == SOCKET_ERROR) return (FALSE); if (length == 0) return (FALSE); if (hdc = GetDC(hWnd)) i1 = wsprintf((lpstr)line1, "TCP Echo Client No.%d", count); i2 = wsprintf((lpstr)line2, "Receive %d bytes",length); i3 = wsprintf((lpstr)line3, "Those are:%c, %c, %c, %c, %c, %c",buffer[0],buffer[1],buffer[2],buffer[100],buffer[1000],buffer[1023]); TextOut(hDc, 10, 2, (LPSTR)line1, i1);

11 TextOut(hDc, 10, 22, (LPSTR)line2, i2); TextOut(hDc, 10, 42, (LPSTR)line3, i3); ReleaseDC(hWnd, hdc); return (TRUE); BOOL SetSelect(HWND hwnd, long levent) if (WSAAsyncSelect(s, hwnd, UM_SOCK, levent) == SOCKET_ERROR) AlertUser(hWnd, "WSAAsyncSelect Failure."); return (FALSE); return (TRUE); BOOL SendPacket(HWND hwnd, int len) int length; if ((length = send(s, lpbuffer, len, 0)) == SOCKET_ERROR) return (FALSE); else if (length!= len) AlertUser(hWnd, "Send Length NOT Match!"); return (FALSE); return (TRUE); 程序 3:SERVER.C #include <sys/types.h> #include <sys/mntent.h> #include <netinet/in.h> #include <sys/socket.h> #include <arpa/inet.h> #define USERPORT #define HOST_IP_ADDR " " main(int argc, char **argv) char buf[1024]; struct sockaddr_in client; struct sockaddr_in server; int s; int ns; int namelen; int pktlen; if ((s=socket(af_inet, SOCK_STREAM, 0))<0)

12 perror("socket()"); return; bzero((char *)&server,sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(userport); server.sin_addr.s_addr = INADDR_ANY; if (bind(s, (struct sockaddr *)&server, sizeof(server))<0) perror("bind()"); return; if (listen(s,1)!=0) perror("listen()"); return; namelen = sizeof(client); if ((ns = accept(s, (struct sockaddr *)&client, &namelen)) ==-1) perror("accept()"); return; for (;;) if ((pktlen = recv(ns,buf,1024,0))<0) perror("recv()"); else if (pktlen == 0) printf("recv():return FAILED,connection is shut down!\n"); else printf("recv():return SUCCESS,packet length = %d\n",pktlen); sleep(1); if (send(ns,buf,pktlen,0)<0) perror("send()"); else printf("send():return SUCCESS,packet length = %d\n",pktlen); close(ns); close(s); printf("server ended successfully\n");

13 3.4 另一个精巧的应用程序实例 -wshout 在本节中, 我们通过一个经过精心选择的例子, 进一步讨论一下 Windows Sockets 编程技术 例如如何编制客户机或服务器程序, 如何应用 TCP 有连接服务 ( 流式套接口 ) 或 UDP 无连接服务 ( 数据报套接口 ), 如何进行阻塞或非阻塞方式的套接口操作等等, 这些都是经常碰到的问题 接下来要介绍的 wshout 程序, 可以通过灵活地设置不同选项来达到上述应用情况的任意组合, 从而基本覆盖了应用 Windows Sockets 编程所可能碰到的问题, 具有很好的研究参考价值 由于该程序思路清晰, 结构精良, 所以我们不打算很详细地剖析每一个语句, 而只是简要介绍一下整个程序的逻辑结构, 并在源程序中加入适当的注释 我们相信, 任何具有基本 C 语言和 Windows 编程经验的读者, 都能很轻松地读懂绝大部分内容 经过仔细咀嚼和推敲后, 更能得到一些编写优质程序的灵感 该程序在 FTP 公司的 PCTCP 支撑环境下调试通过, 不过只要读者拥有任何符合 Windows Sockets 1.1 规范的实现, 也能顺利执行该程序 源程序目录 1. wshout.c wshout 主程序 2. wshout.h wshout 头文件 3. wshout.rc wshout 资源文件 4. ushout.c UDP 客户机程序 5. ulisten.c UDP 服务器程序 6. tshout.c TCP 客户机程序 7. tlisten.c TCP 服务器程序 8. errno.c 获取 WSAE* 错误描述字符串程序 9. resolve.c 客户机 / 服务器启动程序 在编译本程序时, 笔者用的是 BC3.1, 只需做一个 PRJ 工程文件, 将上述.c 文件及 winsock.lib 包括进来就行了 请注意 winsock.h 应在 include 目录或当前目录中,winsock.lib 可利用 winsock.dll 通过 implib 工具来建立 如果读者使用其他的编译器, 可自行作相应的调整, 在此不再赘述 程序逻辑结构

14 w shout.c block noblock errno.c reslove.c TCP UDP Client Server ushout.c ulisten.c tshout.c tlisten.c 图 3-3 w shout 程序逻辑结构图 源程序清单及注释 wshout.c 清单 /* * 文件名 : WSHOUT.C */ /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> #include "wshout.h" #define MAJOR_VERSION 1 #define MINOR_VERSION 2 #define WSA_MAKEWORD(x,y) ((y) * (x)) /* HI:Minor, LO:Major */

15 HANDLE hinst; /* 进程实例句柄 */ HWND hourwnd; /* 主窗口句柄 */ HWND hmaindlg; /* 主对话框句柄 */ int ret; /* 工作变量 */ char prbuf[prbuf_len]; /* 用于显示文本的工作缓冲区 */ SOCKET sd; /* 用于监听连接的套接口描述字 */ long temporary_option = 0L; /* 缺省为阻塞模式 */ long blocking_option = 0L; /* 阻塞模式的全局标识 */ int run_cancelled = 0; /* 指示何时按下了取消按钮 */ int len = 1024; /* 一次写的字节数 */ BOOL running = FALSE; /* 程序的运行状态 */ const int itcp = 1; /* 指定为 TCP Shout */ const int iudp = 2; /* 指定为 UDP Shout */ int iproto = 1; /* 缺省为 TCP Shout */ int iportno = SOCK_SHOUT; int temporary_protocol = 1; /* 在 Settings() 中使用 */ int ishout = 1; int ilisten = 2; int iclientorserver = 1; /* 缺省为 Shout( 客户机 ) */ int tclientorserver = 1; /* 在 Settings() 中使用 */ char HostModeBuf[20];/* 保存模式字符串 */ WORD VersionReqd; LPWSADATA lpmywsadata; int PASCAL WinMain (HANDLE hinstance,handle hprevinstance,lpstr lpcmdline,int ncmdshow) HWND hwnd; MSG msg; BOOL InitApp(HANDLE); if (!hprevinstance) if (!InitApp(hInstance)) return (NULL); hinst = hinstance;

16 hwnd = CreateWindow("MainMenu", "Windows Shout", WS_OVERLAPPEDWINDOW WS_SYSMENU WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinstance, NULL); if (!hwnd) return (NULL); hourwnd = hwnd; while (GetMessage(&msg, NULL, NULL, NULL)) TranslateMessage(&msg); /* 翻译虚拟键码 */ DispatchMessage(&msg); return (msg.wparam); BOOL InitApp(HANDLE hinstance) HANDLE hmemory; PWNDCLASS pwndclass; BOOL bsuccess; hmemory = LocalAlloc(LPTR, sizeof(wndclass)); pwndclass = (PWNDCLASS) LocalLock(hMemory); pwndclass->hcursor = LoadCursor(NULL, IDC_ARROW); pwndclass->hicon = LoadIcon(hInstance, (LPSTR) "SHOUT"); pwndclass->lpszmenuname = (LPSTR) "MainMenu"; pwndclass->lpszclassname = (LPSTR) "MainMenu"; pwndclass->hbrbackground = GetStockObject(WHITE_BRUSH); pwndclass->hinstance = hinstance; pwndclass->style = NULL; pwndclass->lpfnwndproc = ShoutWndProc;

17 bsuccess = RegisterClass(pWndClass); LocalUnlock(hMemory); LocalFree(hMemory); return (bsuccess); long FAR PASCAL ShoutWndProc(HWND hwnd, WORD message,word wparam, LONG lparam) FARPROC lpdialogboxproc; switch (message) case WM_CREATE: /* Put up the dialog box */ lpdialogboxproc = MakeProcInstance(DialogProc, hinst); DialogBox (hinst, (LPSTR) "MainDialog", hwnd, lpdialogboxproc) ; FreeProcInstance(lpDialogBoxProc); PostMessage(hWnd, WM_DESTROY, 0, 0L); case WM_DESTROY: PostQuitMessage(0); default: return(defwindowproc(hwnd, message, wparam, lparam)); return NULL; BOOL FAR PASCAL DialogProc(HWND hourdlg, WORD message, WORD wparam, LONG lparam) FARPROC lpprocabout; FARPROC lpprocsettings; long lret;

18 WORD wmajorversion, wminorversion; char hostnm[64]; /* 包含主机名的工作缓冲区 */ switch (message) case WM_INITDIALOG: /* 选择缺省主机 */ SetDlgItemText(hOurDlg, IDD_HNAME, ""); SendDlgItemMessage(hOurDlg, /* 对话框句柄 */ IDD_HNAME, /* 向何处发送 msg */ EM_SETSEL, /* 选择字符 */ NULL, /* 附加信息 */ MAKELONG(0, 0x7fff)); /* 全部内容 */ SetFocus(GetDlgItem(hOurDlg, IDD_HNAME)); /* 初始化 */ hmaindlg = hourdlg; /* 保存自己的窗口句柄 */ SetDlgItemText(hOurDlg, IDD_COHOST,"Shout to:"); wmajorversion = MAJOR_VERSION; wminorversion = MINOR_VERSION; VersionReqd=WSA_MAKEWORD(wMajorVersion, wminorversion); lpmywsadata = (LPWSADATA)_calloc(1, sizeof(wsadata)); ret = WSAStartup(VersionReqd, lpmywsadata); if (ret!= 0) wshout_err (hourdlg, WSAGetLastError(), "WSAStartup()"); return (TRUE); case WM_CLOSE: PostMessage(hOurDlg, WM_COMMAND, IDM_EXIT, 0L); case WM_SYSCOMMAND: SendMessage(hOurWnd, message, wparam, lparam); case WM_COMMAND: switch (wparam)

19 case IDD_CONNECT: /* 按下连接按钮 */ case IDM_START: /* 选择了 Start 菜单项 */ run_cancelled = FALSE; /* 不能重入 */ if (running) MessageBox(hOurWnd,"Shout is already running!", "Shout", MB_OK MB_APPLMODAL MB_ICONEXCLAMATION); return FALSE; ClearBoxes(hOurDlg); running = TRUE; if (iclientorserver == ishout) /* 确保有主机名 */ if (GetDlgItemText (hourdlg, IDD_HNAME, hostnm, 80) < 2) MessageBeep(0); SetDlgItemText(hOurDlg, running = FALSE; IDD_COMMENT,"No hostname specified"); sd = ResolveAndConnectHost((char FAR *)hostnm,hourdlg,iproto, iportno); if (sd == SOCKET_ERROR) /* 无法创建套接口 */ else running = FALSE; sd = GetSocketAndBind(hOurDlg, iproto, iportno); if (sd == SOCKET_ERROR) running = FALSE; /* Set the I/O mode of the socket */ if (blocking_option) lret = 1L; /* 非阻塞模式 */ ioctlsocket(sd, FIONBIO, (u_long FAR *) &lret);

20 else lret = 0L; /* 阻塞模式 */ ioctlsocket(sd, FIONBIO, (u_long FAR *) &lret); if (iclientorserver == ishout) /* SHOUT */ /* 产生数据并写入套接口 */ if (iproto == itcp) lret = TWriteData(sd, hourdlg, len); else /* UDP */ lret = UWriteData(sd, hourdlg, len); else /* LISTEN */ if (iproto == itcp) lret = TReadData(sd,hOurDlg, len); else /* UDP */ lret = UReadData(sd,hOurDlg, len); closesocket(sd); running = FALSE; case IDD_CANCEL: if (running) /* 停止 */ ret = WSACancelBlockingCall(); run_cancelled = TRUE; if (ret == SOCKET_ERROR) /* WSANOTINITIALISED or WSAENETDOWN or WSAEINVAL */ if (h_errno == WSAENETDOWN) /* Watch out for hacceptsock! */ /* close what is left of the connection */ closesocket(sd); case IDM_EXIT: ret = WSACleanup();

21 if (ret == SOCKET_ERROR && h_errno == WSAEINPROGRESS) MessageBox(hOurWnd, "Data transfer in progress.\nstop transfer first.", "WndProc()", MB_OK MB_APPLMODAL MB_ICONINFORMATION); /* 一个套接口正处于阻塞状态 */ _free((char NEAR *) lpmywsadata); EndDialog(hOurDlg, TRUE) ; /* 退出 */ case IDM_ABOUT: lpprocabout = MakeProcInstance(About, hinst); DialogBox(hInst, "AboutBox", hourdlg, lpprocabout); FreeProcInstance(lpProcAbout); case IDM_SETTINGS: lpprocsettings = MakeProcInstance(Settings, hinst); DialogBox(hInst, "SettingsDialog", hourdlg, lpprocsettings); FreeProcInstance(lpProcSettings); default: /* switch (wparam) */ /* switch (message) */ return FALSE; /* 此函数处理 About 对话框 */ BOOL FAR PASCAL About(HWND hdlg, WORD message, WORD wparam, LONG lparam) char tempbuf[15]; switch (message) case WM_INITDIALOG: SetDlgItemText(hDlg, IDA_COPYRIGHT,(LPSTR)lpmyWSAData->szDescription);

22 wsprintf(tempbuf, "%d.%2d\n",major_version, MINOR_VERSION); SetDlgItemText(hDlg, IDA_APP_VERSION, (LPSTR) tempbuf); wsprintf(tempbuf, "%d.%2d\n", lpmywsadata->wversion%256,lpmywsadata->wversion/256); SetDlgItemText (hdlg, IDA_DLL_VERSION, (LPSTR) tempbuf); return (FALSE); case WM_COMMAND: if (wparam == IDOK wparam == IDCANCEL) EndDialog(hDlg, TRUE); return (TRUE); return (FALSE); /* 此函数处理 Settings 对话框 */ BOOL FAR PASCAL Settings(HWND hdlg, WORD message, WORD wparam, LONG lparam) int buffer_len = len; int port_no = iportno; switch (message) case WM_INITDIALOG: /* Select a default send() buffer length */ SetDlgItemInt(hDlg, IDS_BUFFLEN, len, 0); /* Select a default port number */ SetDlgItemInt(hDlg, IDS_PORTNO, iportno, 0); if (iclientorserver == ishout) /* 程序类型 */ CheckThisProgBoxOn(hDlg, IDS_CLIENT); else CheckThisProgBoxOn(hDlg, IDS_SERVER); if (iproto == itcp) /* 协议类型 */ CheckThisProtoBoxOn(hDlg, IDS_TCP);

23 else CheckThisProtoBoxOn(hDlg, IDS_UDP); if (!blocking_option) /* 阻塞模式 */ CheckThisBoxOn(hDlg, IDS_BLOCK); else CheckThisBoxOn(hDlg, IDS_NOBLOCK); SendDlgItemMessage(hDlg, /* dialog handle */ IDS_PORTNO, /* where to send msg */ EM_SETSEL, /* select characters */ NULL, /* additional info */ MAKELONG(0, 0x7fff)); /* entire contents */ SendDlgItemMessage(hDlg, /* dialog handle */ IDS_BUFFLEN, /* where to send msg */ EM_SETSEL, /* select characters */ NULL, /* additional info */ MAKELONG(0, 0x7fff)); /* entire contents */ SetFocus(GetDlgItem(hDlg, IDS_BUFFLEN)); return (TRUE); case WM_COMMAND: switch (wparam) case IDS_CLIENT: /* USer has set to Shout */ CheckThisProgBoxOn(hDlg, IDS_CLIENT); tclientorserver = ishout; SetDlgItemText(hMainDlg, IDD_COHOST,"Foreign host:"); SetDlgItemText(hMainDlg, IDD_HNAME,""); case IDS_SERVER: /* USer has set to Listen */ CheckThisProgBoxOn(hDlg, IDS_SERVER); tclientorserver = ilisten; SetDlgItemText(hMainDlg, IDD_COHOST,"Listening to:"); SetDlgItemText(hMainDlg, IDD_HNAME,"[Hit 'Start']"); case IDS_TCP: /* USer has set to TCP */ CheckThisProtoBoxOn(hDlg, IDS_TCP);

24 temporary_protocol = itcp; case IDS_UDP: /* USer has set to UDP */ CheckThisProtoBoxOn(hDlg, IDS_UDP); temporary_protocol = iudp; case IDS_BLOCK: /* User has set to blocking mode */ CheckThisBoxOn(hDlg, IDS_BLOCK); temporary_option = 0L; case IDS_NOBLOCK: /* User has set to nonblocking mode */ CheckThisBoxOn(hDlg, IDS_NOBLOCK); temporary_option = 1L; case IDOK: /* 用户已完成对设置的修改 */ buffer_len = GetDlgItemInt(hDlg, IDS_BUFFLEN, NULL, 0); if (buffer_len == 0 buffer_len > 8192) MessageBox(hOurWnd, "Buffer length must be between 1 and 8K", "Settings()", return (FALSE); MB_OK MB_APPLMODAL MB_ICONSTOP); port_no = GetDlgItemInt(hDlg, IDS_PORTNO, NULL, 0); if (port_no == 0) MessageBox(hDlg, "Port number must be between 0 and 65,535", "Settings()", MB_OK MB_APPLMODAL MB_ICONSTOP); return (FALSE); len = buffer_len; iportno = port_no; blocking_option = temporary_option; iproto = temporary_protocol; iclientorserver = tclientorserver; case IDCANCEL:

25 /* 用户不想改变设置 */ EndDialog(hDlg, TRUE); return (TRUE); default: default: return (FALSE); void CheckThisBoxOn(HWND hdlg, int ButtonID) switch (ButtonID) case IDS_BLOCK: CheckDlgButton(hDlg, IDS_BLOCK, 1); CheckDlgButton(hDlg, IDS_NOBLOCK, 0); case IDS_NOBLOCK: CheckDlgButton(hDlg, IDS_BLOCK, 0); CheckDlgButton(hDlg, IDS_NOBLOCK, 1); default: return; void CheckThisProtoBoxOn(HWND hdlg, int ButtonID) switch (ButtonID) case IDS_TCP: CheckDlgButton(hDlg, IDS_TCP, 1); CheckDlgButton(hDlg, IDS_UDP, 0); case IDS_UDP:

26 CheckDlgButton(hDlg, IDS_TCP, 0); CheckDlgButton(hDlg, IDS_UDP, 1); default: return; void CheckThisProgBoxOn(HWND hdlg, int ButtonID) switch (ButtonID) case IDS_CLIENT: /* Shout */ CheckDlgButton(hDlg, IDS_CLIENT, 1); CheckDlgButton(hDlg, IDS_SERVER, 0); case IDS_SERVER: /* Listen */ CheckDlgButton(hDlg, IDS_CLIENT, 0); CheckDlgButton(hDlg, IDS_SERVER, 1); default: return; /* 以下就是我们如何处理 模拟阻塞 - 本函数检查消息队列, 如果发现需要处理的消息, 就返回一个正的值 */ int ShoutBlockingHook (void) MSG msg; /* lets us pull messages via PeekMessage */ int ret = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); if (ret) TranslateMessage(&msg); DispatchMessage(&msg); return ret;

27 char * _calloc (nelem, elsize) unsigned nelem, elsize; HANDLE hmem; PSTR ptr; unsigned size = nelem * elsize; if ((hmem = LocalAlloc(LPTR, size)) == NULL) return (char *) 0; if ((ptr = LocalLock(hMem)) == NULL) LocalFree(hMem); return (char *) 0; return (char *) ptr; void _free (void *cp) (void) LocalFree(LocalHandle((WORD) cp)); void ClearBoxes(HWND hourdlg) wsprintf(prbuf," \n"); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_TIME, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_WRITES,(LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_BYTES, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_BITS, (LPSTR) prbuf); return; /* * wshout_err() 函数 * 描述 :

28 * * 通过错误代码获取相应的错误描述文本, 与用户提供的错误前缀合 * 并, 并显示在对话框中 */ void wshout_err (HWND hourdlg, /* 对话框的窗口句柄 */ int wsa_err, /* WinSock 错误代码 */ char far *err_prefix) /* 错误前缀字符串 */ char errbuf[prbuf_len]; /* 错误描述字符串缓冲区 */ /* 获取错误描述字符串 */ WSAsperror(hInst, wsa_err, (LPSTR)errbuf, PRBUF_LEN); /* 合并错误描述字符串与用户错误前缀字符串 */ wsprintf((lpstr)prbuf, "%s:%s", (LPSTR) err_prefix, (LPSTR)errbuf); /* 在对话框中显示错误文本 */ SetDlgItemText(hOurDlg, IDD_COMMENT, (LPSTR) prbuf); /* end wshout_err() */ /* eof */ wshout.h 清单 /* * 文件名 : WSHOUT.H */ #ifndef _WSHOUT_INC_ #define _WSHOUT_INC_ /* Windows 3.0 头文件 */ #include <windows.h> #define _INC_WINDOWS #include <winsock.h> #ifdef cplusplus extern "C"

29 #endif /* cplusplus */ /* WSHOUT.C 中定义的全局变量 */ extern HANDLE hinst; /* Instance handle */ extern HWND hourwnd; /* Main Window Handle */ extern int ret; /* work variable */ #define PRBUF_LEN 50 extern char prbuf[prbuf_len]; /* work buffer */ /* 菜单 IDs */ #define IDM_START 101 #define IDM_ABOUT 102 #define IDM_STOP 103 #define IDM_EXIT 104 #define IDM_SETTINGS 105 /* 对话框控制 IDs */ #define IDD_HNAME 200 #define IDD_CONNECT IDOK #define IDD_CANCEL IDCANCEL #define IDD_WRITES 208 #define IDD_BYTES 210 #define IDD_BITS 212 #define IDD_HELP 214 #define IDD_SENT 230 #define IDD_WRITE 232 #define IDD_TIME 234 #define IDD_COMMENT 236 #define IDD_COHOST 240 /* Settings 对话框控制 IDs */ #define IDS_BUFFLEN 300 #define IDS_PORTNO 301 #define IDS_BLOCK 302 #define IDS_NOBLOCK 304 #define IDS_TCP 306 #define IDS_UDP 308 #define IDS_CLIENT 310 #define IDS_SERVER 312

30 #define IDS_DEFAULT 314 /* About 对话框控制 IDs */ #define IDA_COPYRIGHT 400 #define IDA_APP_VERSION 402 #define IDA_DLL_VERSION 404 /* 程序控制 IDs */ #define WM_SELECT WM_USER+16 /* 全局变量 */ #define SOCK_DISCARD 9 /* use the UDP ttytst source port for test */ #define SOCK_SHOUT /* TCP port used for SHOUT & LISTEN */ #define BUF_SIZE 8192 #define WRITE_TIMER 1 /* 函数原型 */ int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int); long FAR PASCAL ShoutWndProc(HWND, WORD, WORD, LONG); BOOL FAR PASCAL About(HWND, WORD, WORD, LONG); BOOL FAR PASCAL DialogProc(HWND, WORD, WORD, LONG); BOOL FAR PASCAL Settings(HWND, WORD, WORD, LONG); BOOL InitApp(HANDLE); void CheckThisBoxOn(HWND, int); void CheckThisProtoBoxOn(HWND, int); void CheckThisProgBoxOn(HWND, int); void ClearBoxes(HWND); SOCKET ResolveAndConnectHost(LPSTR, HWND, int, int); SOCKET GetSocketAndBind(HWND, int, int); long UWriteData(SOCKET, HWND, int); long UReadData(SOCKET, HWND, int); long TWriteData(SOCKET, HWND, int); long TReadData(SOCKET, HWND, int); int ShoutBlockingHook (void); int PASCAL FAR WSAsperror (HANDLE, int, char far *, int); void wshout_err (HWND, int, char far *); #define bcopy(a,b,c) _fmemcpy(b,a,c) char * _calloc (unsigned, unsigned); void _free (void *);

31 #ifdef _cplusplus #endif /* cplusplus */ #endif /* ifndef _WSHOUT_INC_ */ /* eof */ wshout.rc 清单 /* * 文件名 : WSHOUT.RC */ #include <windows.h> #include <winsock.h> #include "wshout.h" MainMenu MENU BEGIN POPUP "&File" BEGIN MENUITEM "&Start", IDM_START MENUITEM "Sto&p", IDM_STOP MENUITEM SEPARATOR MENUITEM "E&xit", IDM_EXIT END POPUP "&Options" BEGIN MENUITEM "&Settings...", IDM_SETTINGS MENUITEM SEPARATOR MENUITEM "&About Shout...", IDM_ABOUT END END ABOUTBOX DIALOG 22, 17, 144, 102 CAPTION "About Shout for Windows" STYLE DS_MODALFRAME WS_OVERLAPPED WS_CAPTION WS_SYSMENU BEGIN

32 CTEXT "Windows Shout", -1, 29, 5, 85, 8 CTEXT "Version", -1, 46, 13, 33, 8, SS_CENTER WS_GROUP CTEXT "WINSOCK.DLL \n FTP Software, Inc. \ncopyright 1993", IDA_COPYRIGHT, 38, 40, 68, 25, SS_CENTER WS_GROUP CTEXT "Version", -1, 46, 67, 33, 8, SS_CENTER WS_GROUP CTEXT "num", IDA_DLL_VERSION, 79, 67, 18, 8, SS_CENTER WS_GROUP CONTROL "OK", 1, "BUTTON", BS_DEFPUSHBUTTON WS_GROUP WS_TABSTOP, 56, 82, 32, 14 ICON "SHOUT", -1, 11, 8, 16, 16 CONTROL "num", IDA_APP_VERSION, "STATIC", SS_LEFT WS_GROUP, 79, 13, 18, 8 CONTROL "using", -1, "STATIC", SS_CENTER WS_GROUP, 55, 26, 30, 8 END SettingsDialog DIALOG 9, 16, 172, 117 CAPTION "Settings" STYLE DS_MODALFRAME WS_POPUP WS_CAPTION WS_SYSMENU BEGIN CONTROL " send/recv \nbuffer &length", -1, "STATIC", SS_LEFT WS_GROUP, 84, 8, 48, 20 CONTROL "&Port number", -1, "STATIC", SS_LEFT WS_GROUP, 84, 31, 48, 10 CONTROL "&Blocking", IDS_BLOCK, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 100, 61, 56, 12 CONTROL "&TCP", IDS_TCP, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 20, 60, 41, 12 CONTROL "&Client", IDS_CLIENT, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 19, 15, 35, 12 CONTROL "&Server", IDS_SERVER, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 19, 26, 35, 12 CONTROL "&UDP", IDS_UDP, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 20, 72, 41, 12 CONTROL "&Nonblocking", IDS_NOBLOCK, "BUTTON", BS_AUTOCHECKBOX WS_TABSTOP, 100, 73, 56, 12 CONTROL "O.K.", IDOK, "BUTTON", BS_PUSHBUTTON WS_TABSTOP, 40, 95, 37, 14 CONTROL "Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON WS_TABSTOP, 90, 95, 37, 14 CONTROL "", IDS_BUFFLEN, "EDIT", ES_CENTER WS_BORDER WS_TABSTOP, 130, 11, 36, 12 CONTROL "", IDS_PORTNO, "EDIT", ES_CENTER WS_BORDER WS_TABSTOP, 130, 29, 36, 12 CONTROL "Protocol", 237, "button", BS_GROUPBOX, 6, 49, 70, 38 CONTROL "I/O Mode", 239, "button", BS_GROUPBOX, 90, 49, 70, 38

33 END CONTROL "Program Mode", 241, "button", BS_GROUPBOX, 6, 7, 70, 34 MainDialog DIALOG 17, 32, 163, 135 CAPTION "Windows Shout" MENU MainMenu STYLE DS_ABSALIGN WS_OVERLAPPED WS_CAPTION WS_SYSMENU WS_MINIMIZEBOX BEGIN CONTROL "", IDD_HNAME, "EDIT", ES_CENTER WS_BORDER WS_GROUP WS_TABSTOP, 62, 9, 93, 12 CONTROL "", IDD_WRITE, "STATIC", SS_CENTER SS_NOPREFIX WS_BORDER, 7, 95, 45, 11 CONTROL "", IDD_SENT, "STATIC", SS_CENTER WS_BORDER, 59, 95, 45, 11 CONTROL "", IDD_TIME, "STATIC", SS_CENTER WS_BORDER, 111, 95, 45, 11 CONTROL "", IDD_WRITES, "STATIC", SS_CENTER WS_BORDER, 7, 120, 45, 11 CONTROL "", IDD_BYTES, "STATIC", SS_CENTER WS_BORDER, 59, 120, 45, 11 CONTROL "", IDD_BITS, "STATIC", SS_CENTER WS_BORDER, 111, 120, 45, 11 CONTROL "writes[reads]", 105, "STATIC", SS_CENTER WS_GROUP, 3, 85, 52, 9 CONTROL "writes[reads]/s", 105, "STATIC", SS_CENTER WS_GROUP, 3, 111, 55, 9 CONTROL "bytes", 105, "STATIC", SS_CENTER WS_GROUP, 61, 85, 42, 9 CONTROL "bytes/sec", 105, "STATIC", SS_CENTER WS_GROUP, 61, 111, 42, 9 CONTROL "time (sec)", 105, "STATIC", SS_CENTER WS_GROUP, 111, 85, 45, 9 CONTROL "bits/sec", 105, "STATIC", SS_CENTER WS_GROUP, 113, 111, 42, 9 CONTROL "Host", IDD_COHOST, "STATIC", SS_LEFT, 7, 10, 52, 10 CONTROL "", IDD_COMMENT, "STATIC", SS_CENTER WS_BORDER WS_GROUP, 9, 68, 146, 11 CONTROL "&Start", IDOK, "BUTTON", BS_PUSHBUTTON WS_TABSTOP, 6, 32, 32, 20 CONTROL "Sto&p", IDCANCEL, "BUTTON", BS_PUSHBUTTON WS_TABSTOP, 65, 32, 32, 20 CONTROL "E&xit", IDM_EXIT, "BUTTON", BS_PUSHBUTTON WS_TABSTOP, 125, 32, 32, 20 CONTROL "", -1, "static", SS_BLACKFRAME, 0, 60, 163, 1 END SHOUT ICON wshout.ico /* * 错误描述字符串表 * 用于 WSAsperror() 函数

34 */ STRINGTABLE BEGIN WSABASEERR, "[0] No Error" WSAEINTR, "[10004] Interrupted system call" WSAEBADF, "[10009] Bad file number" WSAEACCES, "[10013] Permission denied" WSAEFAULT, "[10014] Bad address" WSAEINVAL, "[10022] Invalid argument" WSAEMFILE, "[10024] Too many open files" WSAEWOULDBLOCK, "[10035] Operation would block" WSAEINPROGRESS, "[10036] Operation now in progress" WSAEALREADY, "[10037] Operation already in progress" WSAENOTSOCK, "[10038] Socket operation on non-socket" WSAEDESTADDRREQ, "[10039] Destination address required" WSAEMSGSIZE, "[10040] Message too long" WSAEPROTOTYPE, "[10041] Protocol wrong type for socket" WSAENOPROTOOPT, "[10042] Bad protocol option" WSAEPROTONOSUPPORT, "[10043] Protocol not supported" WSAESOCKTNOSUPPORT, "[10044] Socket type not supported" WSAEOPNOTSUPP, "[10045] Operation not supported on socket" WSAEPFNOSUPPORT, "[10046] Protocol family not supported" WSAEAFNOSUPPORT, "[10047] Address family not supported by protocol family" WSAEADDRINUSE, "[10048] Address already in use" WSAEADDRNOTAVAIL, "[10049] Can't assign requested address" WSAENETDOWN, "[10050] Network is down" WSAENETUNREACH, "[10051] Network is unreachable" WSAENETRESET, "[10052] Net dropped connection or reset" WSAECONNABORTED, "[10053] Software caused connection abort" WSAECONNRESET, "[10054] Connection reset by peer" WSAENOBUFS, "[10055] No buffer space available" WSAEISCONN, "[10056] Socket is already connected" WSAENOTCONN, "[10057] Socket is not connected" WSAESHUTDOWN, "[10058] Can't send after socket shutdown" WSAETOOMANYREFS, "[10059] Too many references, can't splice" WSAETIMEDOUT, "[10060] Connection timed out" WSAECONNREFUSED, "[10061] Connection refused" WSAELOOP, "[10062] Too many levels of symbolic links" WSAENAMETOOLONG, "[10063] File name too long" WSAEHOSTDOWN, "[10064] Host is down" WSAEHOSTUNREACH, "[10065] No Route to Host"

35 WSAENOTEMPTY, "[10066] Directory not empty" WSAEPROCLIM, "[10067] Too many processes" WSAEUSERS, "[10068] Too many users" WSAEDQUOT, "[10069] Disc Quota Exceeded" WSAESTALE, "[10070] Stale NFS file handle" WSAEREMOTE, "[10071] Too many levels of remote in path" WSASYSNOTREADY, "[10091] Network SubSystem is unavailable" WSAVERNOTSUPPORTED, "[10092] WINSOCK DLL Version out of range" WSANOTINITIALISED, "[10093] Successful WSASTARTUP not yet performed" WSAHOST_NOT_FOUND, "[11001] Host not found" WSATRY_AGAIN, "[11002] Non-Authoritative Host not found" WSANO_RECOVERY, "[11003] Non-Recoverable errors: FORMERR, REFUSED, NOTIMP" WSANO_DATA, "[11004] Valid name, no data record of requested type" END /* eof */ ushout.c 清单 /* * 文件名 : USHOUT.C */ #include "wshout.h" /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> /* Returns the number of bytes written */ long UWriteData(SOCKET hsock, HWND hourdlg, int send_len) int counter; static int DataBuffer[BUF_SIZE]; /* Buffer to hold generated data */ static char ReplyBuffer[512]; /* Buffer to hold any reply rcvd */

36 long bytes_sent = 0L; /* Counter of bytes on connection */ long total_len = 1024L*1024L; /* Total # of bytes to generate */ time_t start, end; /* variables to hold read timing */ long total_time = 0L; /* variable to hold delta t */ long write_count = 0L; /* number of times */ long tmp = 0L; /* holds count for bytes written */ long ltemp = 0L; int i_temp; extern int run_cancelled; struct sockaddr_in dest; /* Destination machine address structure */ /* What makes shout unique is that it generates data* * in memory (as opposed to accessing the disk). * * This tests the 'raw' speed of the TCP connection * * as the rate-limiting access time is eliminated. * * First, generate the data and place it into an * * array, data_buffer: */ for (counter = 0; counter < BUF_SIZE; counter++) DataBuffer[counter] = counter; /* Write data on the descriptor like a banshee, * careful to time the writes and count data * transmitted: */ SetDlgItemText(hOurDlg, IDD_COMMENT, "Sending UDP Data..."); time( &start ); while (bytes_sent < total_len)/* while still bytes to send */ do ; while (ShoutBlockingHook()); /* Dispatch messages if any */ if (run_cancelled) WSASetLastError(WSAEINTR); /* Non-blocking mode was cancelled */ tmp = send(hsock, (char FAR *) &DataBuffer, send_len, 0); if (tmp == SOCKET_ERROR)

37 if (h_errno == WSAEWOULDBLOCK) /* if no data, read again */ continue; else wshout_err (hourdlg, WSAGetLastError(), "send()"); /* Calc. time elapsed & stats about any data sent */ time(&end); if (total_time = (long) difftime(end, start)) /* Print the statistics gathered */ wsprintf((lpstr)prbuf,"%ld\n",write_count); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); wsprintf((lpstr)prbuf,"%ld\n",bytes_sent); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); wsprintf((lpstr)prbuf,"%ld\n",total_time); SetDlgItemText(hOurDlg, IDD_TIME, (LPSTR) prbuf); ltemp = write_count/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_WRITES,(LPSTR) prbuf); ltemp = bytes_sent/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BYTES, (LPSTR) prbuf); ltemp = 8 * (bytes_sent/total_time); wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BITS, (LPSTR) prbuf); /* exit from the while loop */ /* end if (total_time) */ write_count++; /* incr. counter of times written */ bytes_sent += tmp; /* # of bytes placed on connection */ wsprintf((lpstr)prbuf,"%ld\n",bytes_sent); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); /* end if (tmp == -1) */ write_count++; /* incr. counter of times written */

38 bytes_sent += tmp; /* # of bytes placed on connection */ wsprintf((lpstr)prbuf,"%ld\n",write_count); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); wsprintf((lpstr)prbuf,"%ld\n",bytes_sent); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); /* end while */ /* Look for a reply... NOTE: most hosts won't give * a 'reply', done to illustrate communication between * sockets. Our ulisten example will give a reply though. */ SetDlgItemText(hOurDlg, IDD_COMMENT, "Waiting for reply from server..\n"); while (1) tmp = sizeof(dest); i_temp = recvfrom(hsock,(char FAR *) &ReplyBuffer,sizeof(ReplyBuffer), 0, (struct sockaddr *)&dest,(int FAR *)&tmp); if (i_temp == SOCKET_ERROR) if (h_errno == WSAEWOULDBLOCK) /* if no data, read again */ continue; else /* any error besides these. just punt */ wshout_err (hourdlg, WSAGetLastError(), "recvfrom()"); /* end if (i_temp == SOCKET_ERROR) */ /* else got a reply...*/ wsprintf((lpstr)prbuf, "Server: %s\n", (LPSTR) ReplyBuffer); SetDlgItemText(hOurDlg, IDD_COMMENT, prbuf); /* end while(1) */ /* All done */ return bytes_sent; /* eof */

39 ulisten.c 清单 /* * 文件名 : ULISTEN.C */ #include "wshout.h" /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> /* Returns the number of bytes written */ long UReadData(SOCKET hsock, HWND hourdlg, int read_len) static char ReadBuf[BUF_SIZE]; static char SendBuf[512]; struct sockaddr_in local; /* Local machine address structure */ int i; /* General purpose return code */ long total_time = 0L; /* variable to hold delta t */ int tmp, len = 0; int num_reads = 0; long bytes_read = 0L; long last_time, now, timeout = 15L; long ltemp; extern int run_cancelled; BOOL btemp = TRUE; SetDlgItemText(hOurDlg, IDD_COMMENT, "Awaiting the UDP Data..."); SetDlgItemText(hOurDlg, IDD_HNAME, " "); time(&now); time(&last_time); while (last_time + timeout > now) time(&now); tmp = sizeof(local); do

40 ; while (ShoutBlockingHook()); /* Dispatch messages while available */ if (run_cancelled) WSASetLastError(WSAEINTR); /* Non-blocking mode was cancelled */ len = recvfrom(hsock, ReadBuf, read_len, 0, (struct sockaddr *)&local,&tmp); if (len == SOCKET_ERROR) if (h_errno == WSAEWOULDBLOCK) /* if no data, read again */ continue; /* end: if (errno == WSAEWOULDBLOCK) */ else if (bytes_read) wshout_err (hourdlg, WSAGetLastError(), "recvfrom()"); /* end else */ /* end: if (len == SOCKET_ERROR) */ if (btemp) /* To update our main display once */ /* Do not use wsprintf() or you will add an extra char */ _fmemcpy(prbuf, inet_ntoa(local.sin_addr), 4*sizeof(u_long)); SetDlgItemText(hOurDlg, IDD_HNAME, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_COMMENT, "Reading UDP Data..."); btemp = FALSE; num_reads++; if (len!= SOCKET_ERROR) bytes_read += len; /* Print the statistics gathered */ wsprintf((lpstr)prbuf,"%d\n",num_reads); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); wsprintf((lpstr)prbuf,"%ld\n",bytes_read); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); time(&last_time);

41 /* end: while */ total_time = timeout; wsprintf((lpstr)prbuf,"%ld\n",total_time); SetDlgItemText(hOurDlg, IDD_TIME, (LPSTR) prbuf); ltemp = num_reads/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_WRITES,(LPSTR) prbuf); ltemp = bytes_read/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BYTES, (LPSTR) prbuf); ltemp = 8 * (bytes_read/total_time); wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BITS, (LPSTR) prbuf); if (bytes_read) SetDlgItemText(hOurDlg, IDD_COMMENT, "...UDP Listen Done\n"); /* end: if (bytes_read) */ else wsprintf((lpstr)prbuf, "Timed out. No data received.\n"); SetDlgItemText(hOurDlg, IDD_COMMENT, prbuf); goto come_here; /* end: else */ /* send reply to 'client' */ wsprintf((lpstr)prbuf, "Replied to %s\n", inet_ntoa(local.sin_addr)); SetDlgItemText(hOurDlg, IDD_COMMENT, prbuf); for (i=0; i<10; ++i) sprintf(sendbuf, "Rec'd %ld bytes.\n", bytes_read); if(len = sendto(hsock, SendBuf, sizeof(sendbuf), 0, (struct sockaddr FAR *)&local,sizeof(local))) if (len == SOCKET_ERROR) /* if could not send bec. */ if (h_errno == WSAEWOULDBLOCK) continue; wshout_err (hourdlg, WSAGetLastError(), "sendto()");

42 /* end: if (len == -1) */ /* end: if (len = sendto()) */ /* end for */ come_here: return (bytes_read); /* eof */ tshout.c 清单 /* * 文件名 : TSHOUT.C */ #include "wshout.h" /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> /* Returns the number of bytes written */ long TWriteData(SOCKET hsock, HWND hourdlg, int send_len) int counter; static int DataBuffer[BUF_SIZE]; /* Buffer to hold generated data */ long total_len = 1024L*1024L; /* Total # of bytes to generate */ long bytes_sent = 0L; /* Counter of bytes on connection */ int tmp = 0; /* holds count for bytes written */ long write_count = 0L; /* number of times */ time_t start, end; /* variables to hold read timing */ long total_time = 0L; /* variable to hold delta t */ long ltemp = 0L; extern int run_cancelled;

43 /* What makes shout unique is that it generates data* * in memory (as opposed to accessing the disk). * * This tests the 'raw' speed of the TCP connection * * as the rate-limiting access time is eliminated. * * First, generate the data and place it into an * * array, data_buffer: */ for (counter = 0; counter < BUF_SIZE; counter++) DataBuffer[counter] = counter; /* Write data on the descriptor like a banshee, * careful to time the writes and count data * transmitted: */ SetDlgItemText(hOurDlg, IDD_COMMENT, "...Sending TCP Data"); time(&start); while ( bytes_sent < total_len) /* while still bytes to send... */ do ; while (ShoutBlockingHook()); /* Dispatch messages if any */ if (run_cancelled) WSASetLastError(WSAEINTR); /* Non-blocking mode was cancelled */ tmp = send(hsock, (char FAR*) &DataBuffer, send_len, 0); if (tmp == SOCKET_ERROR) if (h_errno == WSAEWOULDBLOCK) continue; else wshout_err (hourdlg, WSAGetLastError(), "send()"); /* Calc. time elapsed & stats about any data sent */ time(&end); /* exit from the while loop */ /* end if (tmp == -1) */

44 write_count++; /* incr. counter of times written */ bytes_sent += tmp; /* total # of bytes placed on connection*/ wsprintf(prbuf,"%ld\n",write_count); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); wsprintf(prbuf,"%ld\n",bytes_sent); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); /* end while */ time(&end); if (total_time = (long) difftime(end, start)) /* Print the statistics gathered */ wsprintf((lpstr)prbuf,"%ld\n",total_time); SetDlgItemText(hOurDlg, IDD_TIME, (LPSTR) prbuf); ltemp = write_count/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_WRITES,(LPSTR) prbuf); ltemp = bytes_sent/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BYTES, (LPSTR) prbuf); ltemp = 8 * (bytes_sent/total_time); wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BITS, (LPSTR) prbuf); /* end if (total_time) */ /* All done */ SetDlgItemText(hOurDlg, IDD_COMMENT, "...TCP Shout Done"); return bytes_sent; /* eof */ tlisten.c 清单 /* * 文件名 :TLISTEN.C */

45 #include "wshout.h" /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> /* Returns the number of bytes written */ long TReadData(SOCKET hsock, HWND hourdlg, int read_len) static char ReadBuf[BUF_SIZE]; SOCKET hacceptsock; struct sockaddr_in local; /* Local machine address structure */ long total_time = 0L; /* variable to hold delta t */ int tmp, len = 0; int num_reads = 0; long bytes_read = 0L; long last_time = 0L; long now = 0L; long ltemp; extern long blocking_option; extern int run_cancelled; struct linger AcceptLinger; BOOL running = FALSE; BOOL btemp = TRUE; SetDlgItemText(hOurDlg, IDD_COMMENT, "Awaiting the TCP Data..."); SetDlgItemText(hOurDlg, IDD_HNAME, " "); tmp = sizeof(local); if (!blocking_option) hacceptsock = accept(hsock,(struct sockaddr FAR *)&local, (int FAR *)&tmp); else for (;;)

46 do ; while (ShoutBlockingHook()); /* Dispatch messages if any */ if (run_cancelled) WSASetLastError(WSAEINTR); /* Non-blocking mode was cancelled */ hacceptsock = accept(hsock,(struct sockaddr FAR *)&local, (int FAR *)&tmp); if (hacceptsock == INVALID_SOCKET) if (h_errno == WSAEWOULDBLOCK) /* Try again */ ; else /* Fatal error -- pop out. */ /* end if ((hacceptsock =.. */ else /* Success -- pop out. */ /* end for */ /* end else */ if (hacceptsock == INVALID_SOCKET) wshout_err (hourdlg, WSAGetLastError(), "accept()"); return 0; /* Now, read the data as fast as we can until no more to read */ time(&last_time); do do ; while (ShoutBlockingHook()); /* Dispatch messages while available */ if (run_cancelled) WSASetLastError(WSAEINTR);

47 /* Non-blocking mode was cancelled */ len = recv(hacceptsock, ReadBuf, read_len, 0); if (len == SOCKET_ERROR) if (h_errno == WSAEWOULDBLOCK) continue; else else if (len == 0) num_reads++; bytes_read += len; wsprintf((lpstr)prbuf,"%d\n",num_reads); SetDlgItemText(hOurDlg, IDD_WRITE, (LPSTR) prbuf); wsprintf((lpstr)prbuf,"%ld\n",bytes_read); SetDlgItemText(hOurDlg, IDD_SENT, (LPSTR) prbuf); if (btemp) /* To update our main display once */ /* Do not use wsprintf() or you will add an extra char */ _fmemcpy(prbuf, inet_ntoa(local.sin_addr), 4*sizeof(u_long)); SetDlgItemText(hOurDlg, IDD_HNAME, (LPSTR) prbuf); SetDlgItemText(hOurDlg, IDD_COMMENT, "Reading TCP Data..."); btemp = FALSE; while ((len!= 0) (len!= SOCKET_ERROR)); time (&now); if (len == SOCKET_ERROR) if ((h_errno == WSAESHUTDOWN) (h_errno == WSAENOTCONN)) /* nothing available for read. */ wsprintf((lpstr)prbuf, "Connection from %s closed.\n",inet_ntoa(local.sin_addr)); SetDlgItemText(hOurDlg, IDD_COMMENT, prbuf); else /* Other error */ wshout_err (hourdlg, WSAGetLastError(), "recv()");

48 else if (len == 0) /* Other side shut down the connection */ wsprintf((lpstr)prbuf, "Connection from %s closed.\n",inet_ntoa(local.sin_addr)); SetDlgItemText(hOurDlg, IDD_COMMENT, prbuf); AcceptLinger.l_onoff = 1; AcceptLinger.l_linger = 0; ret = setsockopt(hacceptsock, SOL_SOCKET, SO_LINGER, (char FAR *) &AcceptLinger, sizeof(acceptlinger)); if (ret == SOCKET_ERROR) wshout_err (hourdlg, WSAGetLastError(), "setsockopt()"); ret = closesocket(hacceptsock); if (ret == SOCKET_ERROR) wshout_err (hourdlg, WSAGetLastError(), "closesocket()"); total_time = (long) difftime(now, last_time); if (total_time == 0) total_time = 1L; /* Avoid dividing by zero */ wsprintf((lpstr)prbuf,"%ld\n",total_time); SetDlgItemText(hOurDlg, IDD_TIME, (LPSTR) prbuf); ltemp = num_reads/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_WRITES,(LPSTR) prbuf); ltemp = bytes_read/total_time; wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BYTES, (LPSTR) prbuf); ltemp = 8 * (bytes_read/total_time); wsprintf((lpstr)prbuf,"%ld\n", ltemp); SetDlgItemText(hOurDlg, IDD_BITS, (LPSTR) prbuf);

49 if (bytes_read) SetDlgItemText(hOurDlg, IDD_COMMENT, "...TCP Listen Done\n"); /* end: if (bytes_read) */ return (bytes_read); /* eof */ errno.c 清单 #include <windows.h> #include <winsock.h> /* * 文件名 : ERRNO.C */ /* * Function: WSAsperror() * * Description: * * Copies string corresponding to the error code provided * into buf, maximum length len. Returns length actually * copied to buffer, or zero if error code is unknown. * String resources should be present for each error code * using the value of the code as the string ID (except for * error = 0, which is mapped to WSABASEERR to keep it with * the others). The DLL is free to use any string IDs that * are less than WSABASEERR for its own use. * */ int PASCAL FAR WSAsperror (HANDLE hinst, /* Instance Handle */ int errorcode, /* WSA Error Number */ char far * buf, /* Buffer for error string */ int len) /* Length of buffer */ int err_len; /* length of error text */

50 if (errorcode == 0) /* If error passed is 0, use the */ errorcode = WSABASEERR; /* base resource file number */ if (errorcode < WSABASEERR) /* If invalid Error code */ return 0; /* return string length of zero */ /* error string from the table in the Resource file into buffer */ err_len = LoadString(hInst,errorcode,buf,len); return (err_len); /* return length of error string retrieved */ /* end WSAsperror() */ /* eof */ resolve.c 清单 /* * 文件名 : RESOLVE.C */ #include "wshout.h" /* MSC Include files: */ #include <stdio.h> #include <io.h> #include <string.h> #include <stdlib.h> #include <time.h> SOCKET ResolveAndConnectHost(LPSTR lphostname,hwnd hourdlg,int iproto, int isockport) struct hostent FAR *host_ptr; /* Ptr to the host name */ struct sockaddr_in dest; /* Addr of target host */ SOCKET hsock; /* The socket to create */ int isocktype; extern int itcp; extern int iudp;

51 /* Internet family addressing */ dest.sin_family = PF_INET; if (iproto == itcp) isocktype = SOCK_STREAM; else if (iproto == iudp) isocktype = SOCK_DGRAM; else return (SOCKET) -1; /* Unknown protocol */ /* default port to connect to. Must be in network byte order */ dest.sin_port = htons((u_int) isockport); SetDlgItemText(hOurDlg, IDD_COMMENT,"Resolving hostname..."); /* Resolve the host name */ host_ptr = gethostbyname(lphostname); if (host_ptr == NULL) wshout_err (hourdlg, WSAGetLastError(), "gethostbyname()"); return (SOCKET) -1; /* Patch host address into struct describing conn: */ bcopy(host_ptr->h_addr,&dest.sin_addr,host_ptr->h_length); /* Allocate a network (socket) descriptor: */ hsock = socket(pf_inet, isocktype, 0); if (hsock == INVALID_SOCKET) wshout_err (hourdlg, WSAGetLastError(), "socket()"); return (SOCKET) -1; /* Start connection process to host described in 'dest' * * struct. */ SetDlgItemText(hOurDlg, IDD_COMMENT, "Connecting..."); ret=connect(hsock,(struct sockaddr FAR *)&dest,sizeof(dest)); if (ret == SOCKET_ERROR) wshout_err (hourdlg, WSAGetLastError(), "connect()");

Microsoft Word - WINDOWS SOCKETS 规范及应用.DOC

Microsoft Word - WINDOWS SOCKETS 规范及应用.DOC Windows Sockets 规范及应用 -Windows 网络编程接口 施炜李铮秦颍编著 ************************************************************* ***** 版权信息 本书作者保留所有版权 禁止任何商业性的转载或复制 非赢利性质的转载和复制不得修改文章内容, 并请保留此段文字 Copyright (c) 1995-1996 By

More information

ebook35-21

ebook35-21 21 Linux L i n u x 211 U N I X U N I X I / O F I F O U N I X I n t e r n e t s o c k e t () s o c k e t () send() r e c v ( read() w r i t e () send() r e c v () I n t e r n e t 212 Internet Internet S

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

Chapter #

Chapter # 第三章 TCP/IP 协议栈 本章目标 通过本章的学习, 您应该掌握以下内容 : 掌握 TCP/IP 分层模型 掌握 IP 协议原理 理解 OSI 和 TCP/IP 模型的区别和联系 TCP/IP 介绍 主机 主机 Internet TCP/IP 早期的协议族 全球范围 TCP/IP 协议栈 7 6 5 4 3 应用层表示层会话层传输层网络层 应用层 主机到主机层 Internet 层 2 1 数据链路层

More information

穨control.PDF

穨control.PDF TCP congestion control yhmiu Outline Congestion control algorithms Purpose of RFC2581 Purpose of RFC2582 TCP SS-DR 1998 TCP Extensions RFC1072 1988 SACK RFC2018 1996 FACK 1996 Rate-Halving 1997 OldTahoe

More information

Simulator By SunLingxi 2003

Simulator By SunLingxi 2003 Simulator By SunLingxi sunlingxi@sina.com 2003 windows 2000 Tornado ping ping 1. Tornado Full Simulator...3 2....3 3. ping...6 4. Tornado Simulator BSP...6 5. VxWorks simpc...7 6. simulator...7 7. simulator

More information

ARP ICMP

ARP ICMP ARP ICMP 2 9-1 ARP 9-2 ARP 9-3 ARP 9-4 ICMP 9-5 ICMP 9-6 ICMP 9-7 ICMP 3 ARP ICMP TCP / IP, IP ARP ICMP 3 IP, ARP ICMP IP ARP ICMP 2, 4 9-1 ARP, MAC, IP IP, MAC ARP Address Resolution Protocol, OSI ARP,,

More information

WinSockÍøÂç±à³Ì

WinSockÍøÂç±à³Ì WinSock 网络编程 1. 概述 80's 初,ARPA( 美国国防部高级研究计划局 ) fi 加利福尼亚大学 Berkeley 分校提供资金,fi 开发在 UNIX 下实现 TCP/IP 协议 fi 为 TCP/IP 开发了一个 API Socket 接口 ( 套接口 ) 俗称 Bekeley 套接口模型 90's 初,Microsoft 等公司 fi 基于 Bekeley 套接口模型 fi

More information

IP505SM_manual_cn.doc

IP505SM_manual_cn.doc IP505SM 1 Introduction 1...4...4...4...5 LAN...5...5...6...6...7 LED...7...7 2...9...9...9 3...11...11...12...12...12...14...18 LAN...19 DHCP...20...21 4 PC...22...22 Windows...22 TCP/IP -...22 TCP/IP

More information

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco

Windows RTEMS 1 Danilliu MMI TCP/IP QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos eco Windows RTEMS 1 Danilliu MMI TCP/IP 80486 QEMU i386 QEMU ARM POWERPC i386 IPC PC104 uc/os-ii uc/os MMI TCP/IP i386 PORT Linux ecos Linux ecos ecos ecos Email www.rtems.com RTEMS ecos RTEMS RTEMS Windows

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

PIC_SERVER (11) SMTP ( ) ( ) PIC_SERVER (10) SMTP PIC_SERVER (event driven) PIC_SERVER SMTP 1. E-

PIC_SERVER (11) SMTP  ( ) ( ) PIC_SERVER (10) SMTP  PIC_SERVER (event driven)  PIC_SERVER SMTP  1.  E- (2005-02-01) (2005-04-28) PIC_SERVER (10) SMTP E-mail PIC_SERVER (event driven) E-mail PIC_SERVER SMTP E-mail 1. E-mail E-mail 1 (1) (2) (3) (4) 1 1. 2 E-mail A E-mail B E-mail SMTP(Simple Mail Transfer

More information

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; Memory & Pointer trio@seu.edu.cn 2.1 2.1.1 1 int *p int a 0x00C7 0x00C7 0x00C7 2.1.2 2 int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++; 2.1.3 1. 2. 3. 3 int A,

More information

C6_ppt.PDF

C6_ppt.PDF C01-202 1 2 - (Masquerade) (Replay) (Message Modification) (Denial of Service) - ( ) (Eavesdropping) (Traffic Analysis) 8 1 2 7 3 6 5 4 3 - TCP SYN (SYN flood) Smurf Ping of Death LAND Attack Teardrop

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

ebook140-8

ebook140-8 8 Microsoft VPN Windows NT 4 V P N Windows 98 Client 7 Vintage Air V P N 7 Wi n d o w s NT V P N 7 VPN ( ) 7 Novell NetWare VPN 8.1 PPTP NT4 VPN Q 154091 M i c r o s o f t Windows NT RAS [ ] Windows NT4

More information

Go构建日请求千亿微服务最佳实践的副本

Go构建日请求千亿微服务最佳实践的副本 Go 构建 请求千亿级微服务实践 项超 100+ 700 万 3000 亿 Goroutine & Channel Goroutine Channel Goroutine func gen() chan int { out := make(chan int) go func(){ for i:=0; i

More information

ebook12-1

ebook12-1 API N e t B I O S Wi n s o c k A P I Wi n s o c k 1 N e t B I O S Wi n s o c k A P I N e t B I O S O S / 2 D O S 2 3 4 Wi n d o w s Wi n d o w s 1 NetBIOS Network Basic Input/Output System, NetBIOS A P

More information

Bus Hound 5

Bus Hound 5 Bus Hound 5.0 ( 1.0) 21IC 2007 7 BusHound perisoft PC hound Bus Hound 6.0 5.0 5.0 Bus Hound, IDE SCSI USB 1394 DVD Windows9X,WindowsMe,NT4.0,2000,2003,XP XP IRP Html ZIP SCSI sense USB Bus Hound 1 Bus

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

概述

概述 OPC Version 1.6 build 0910 KOSRDK Knight OPC Server Rapid Development Toolkits Knight Workgroup, eehoo Technology 2002-9 OPC 1...4 2 API...5 2.1...5 2.2...5 2.2.1 KOS_Init...5 2.2.2 KOS_InitB...5 2.2.3

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

1.ai

1.ai HDMI camera ARTRAY CO,. LTD Introduction Thank you for purchasing the ARTCAM HDMI camera series. This manual shows the direction how to use the viewer software. Please refer other instructions or contact

More information

ebook50-15

ebook50-15 15 82 C / C + + Developer Studio M F C C C + + 83 C / C + + M F C D L L D L L 84 M F C MFC DLL M F C 85 MFC DLL 15.1 82 C/C++ C C + + D L L M F C M F C 84 Developer Studio S t u d i o 292 C _ c p l u s

More information

Microsoft Word - template.doc

Microsoft Word - template.doc HGC efax Service User Guide I. Getting Started Page 1 II. Fax Forward Page 2 4 III. Web Viewing Page 5 7 IV. General Management Page 8 12 V. Help Desk Page 13 VI. Logout Page 13 Page 0 I. Getting Started

More information

untitled

untitled Lwip Swedish Institute of Computer Science February 20, 2001 Adam Dunkels adam@sics.se (QQ: 10205001) (QQ: 329147) (QQ:3232253) (QQ:3232253) QQ ARM TCPIP LCD10988210 LWIP TCP/IP LWIP LWIP lwip API lwip

More information

슬라이드 1

슬라이드 1 2018-2019 年度第二学期 00106501 计算机图形学 童伟华管理科研楼 1205 室 E-mail: tongwh@ustc.edu.cn 中国科学技术大学数学科学学院 http://math.ustc.edu.cn/ 附讲五 Windows 编程 (API) 2 Windows 操作系统简史 1981 年,Chase Bishop 提出 Interface Manager 模型 1985

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

Symantec™ Sygate Enterprise Protection 防护代理安装使用指南

Symantec™ Sygate Enterprise Protection 防护代理安装使用指南 Symantec Sygate Enterprise Protection 防 护 代 理 安 装 使 用 指 南 5.1 版 版 权 信 息 Copyright 2005 Symantec Corporation. 2005 年 Symantec Corporation 版 权 所 有 All rights reserved. 保 留 所 有 权 利 Symantec Symantec 徽 标 Sygate

More information

AL-M200 Series

AL-M200 Series NPD4754-00 TC ( ) Windows 7 1. [Start ( )] [Control Panel ()] [Network and Internet ( )] 2. [Network and Sharing Center ( )] 3. [Change adapter settings ( )] 4. 3 Windows XP 1. [Start ( )] [Control Panel

More information

ebook140-11

ebook140-11 11 VPN Windows NT4 B o r d e r M a n a g e r VPN VPN V P N V P N V P V P N V P N TCP/IP 11.1 V P N V P N / ( ) 11.1.1 11 V P N 285 2 3 1. L A N LAN V P N 10MB 100MB L A N VPN V P N V P N Microsoft PPTP

More information

/ / (FC 3)...

/ / (FC 3)... Modbus/TCP 1.0 1999 3 29 Andy Swales Schneider aswales@modicon.com ... 2 1.... 3 2.... 3 2.1.. 3 2.2..4 2.3..4 2.4... 5 3.... 5 3.1 0... 5 3.2 1... 5 3.3 2... 6 3.4 / /... 7 4.... 7 5.... 8 5.1 0... 9

More information

新版 明解C++入門編

新版 明解C++入門編 511!... 43, 85!=... 42 "... 118 " "... 337 " "... 8, 290 #... 71 #... 413 #define... 128, 236, 413 #endif... 412 #ifndef... 412 #if... 412 #include... 6, 337 #undef... 413 %... 23, 27 %=... 97 &... 243,

More information

(Methods) Client Server Microsoft Winsock Control VB 1 VB Microsoft Winsock Control 6.0 Microsoft Winsock Control 6.0 1(a). 2

(Methods) Client Server Microsoft Winsock Control VB 1 VB Microsoft Winsock Control 6.0 Microsoft Winsock Control 6.0 1(a). 2 (2005-01-26) (2005-01-26) (2005-02-27) PIC_SERVER (9) VB TCP/UDP Visual Basic Microsoft Winsock Control (MSWINSCK.OCX) UDP TCP Client Server Visual Basic UDP/TCP PIC_SERVER UDP/TCP 1. Microsoft Winsock

More information

WWW PHP

WWW PHP WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,

More information

AL-MX200 Series

AL-MX200 Series PostScript Level3 Compatible NPD4760-00 TC Seiko Epson Corporation Seiko Epson Corporation ( ) Seiko Epson Corporation Seiko Epson Corporation Epson Seiko Epson Corporation Apple Bonjour ColorSync Macintosh

More information

C语言的应用.PDF

C语言的应用.PDF AVR C 9 1 AVR C IAR C, *.HEX, C,,! C, > 9.1 AVR C MCU,, AVR?! IAR AVR / IAR 32 ALU 1KBytes - 8MBytes (SPM ) 16 MBytes C C *var1, *var2; *var1++ = *--var2; AVR C 9 2 LD R16,-X ST Z+,R16 Auto (local

More information

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1 21 , 7, Windows,,,, : 010-62782989 13501256678 13801310933,,,, ;,, ( CIP) /,,. : ;, 2005. 11 ( 21 ) ISBN 7-81082 - 634-4... - : -. TP316-44 CIP ( 2005) 123583 : : : : 100084 : 010-62776969 : 100044 : 010-51686414

More information

FY.DOC

FY.DOC 高 职 高 专 21 世 纪 规 划 教 材 C++ 程 序 设 计 邓 振 杰 主 编 贾 振 华 孟 庆 敏 副 主 编 人 民 邮 电 出 版 社 内 容 提 要 本 书 系 统 地 介 绍 C++ 语 言 的 基 本 概 念 基 本 语 法 和 编 程 方 法, 深 入 浅 出 地 讲 述 C++ 语 言 面 向 对 象 的 重 要 特 征 : 类 和 对 象 抽 象 封 装 继 承 等 主

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

Microsoft PowerPoint - ch6 [相容模式]

Microsoft PowerPoint - ch6 [相容模式] UiBinder wzyang@asia.edu.tw UiBinder Java GWT UiBinder XML UI i18n (widget) 1 2 UiBinder HelloWidget.ui.xml: UI HelloWidgetBinder HelloWidget.java XML UI Owner class ( Composite ) UI XML UiBinder: Owner

More information

untitled

untitled MPICH anzhulin@sohu.com 1 MPICH for Microsoft Windows 1.1 MPICH for Microsoft Windows Windows NT4/2000/XP Professional Server Windows 95/98 TCP/IP MPICH MS VC++ 6.x MS VC++.NET Compaq Visual Fortran 6.x

More information

epub83-1

epub83-1 C++Builder 1 C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r C + + B u i l d e r 1.1 1.1.1 1-1 1. 1-1 1 2. 1-1 2 A c c e s s P a r a d o x Visual FoxPro 3. / C / S 2 C + + B u i l d e r / C

More information

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO Car DVD New GUI IR Flow User Manual V0.1 Jan 25, 2008 19, Innovation First Road Science Park Hsin-Chu Taiwan 300 R.O.C. Tel: 886-3-578-6005 Fax: 886-3-578-4418 Web: www.sunplus.com Important Notice SUNPLUS

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

More information

SA-DK2-U3Rユーザーズマニュアル

SA-DK2-U3Rユーザーズマニュアル USB3.0 SA-DK2-U3R 2007.0 2 3 4 5 6 7 8 System Info. Manual Rebuild Delete RAID RAID Alarm Rebuild Rate Auto compare Temp Management Load Default Elapse time Event Log 0 2 3 4 2 3 4 ESC 5

More information

VoIP Make a Rtp Call VoIP Abstract... 2 VoIP RTP...3 Socket IP...9 Config Two Voice-hub

VoIP Make a Rtp Call VoIP Abstract... 2 VoIP RTP...3 Socket IP...9 Config Two Voice-hub VoIP... 2... 2 Abstract... 2... 3... 3 RTP...3 Socket...4...6...7 IP...9 Config Two Voice-hub... 10 1 12 VoIP VoIP voice-hub voice-hub Abstract At the beginning of this paper, we introducted the essential

More information

Oracle 4

Oracle 4 Oracle 4 01 04 Oracle 07 Oracle Oracle Instance Oracle Instance Oracle Instance Oracle Database Oracle Database Instance Parameter File Pfile Instance Instance Instance Instance Oracle Instance System

More information

TX-NR3030_BAS_Cs_ indd

TX-NR3030_BAS_Cs_ indd TX-NR3030 http://www.onkyo.com/manual/txnr3030/adv/cs.html Cs 1 2 3 Speaker Cable 2 HDMI OUT HDMI IN HDMI OUT HDMI OUT HDMI OUT HDMI OUT 1 DIGITAL OPTICAL OUT AUDIO OUT TV 3 1 5 4 6 1 2 3 3 2 2 4 3 2 5

More information

Computer Architecture

Computer Architecture ECE 3120 Computer Systems Assembly Programming Manjeera Jeedigunta http://blogs.cae.tntech.edu/msjeedigun21 Email: msjeedigun21@tntech.edu Tel: 931-372-6181, Prescott Hall 120 Prev: Basic computer concepts

More information

LSC操作说明

LSC操作说明 1 C H R I S T A L P H A 1-4 LSC 型 Part. No. 102041 A L P H A 2-4 LSC 型 Part. No. 10204 冷 冻 干 燥 机 操 作 说 明 新 研 制 的 LSC-8 控 制 器, 具 备 图 形 显 示 功 能, 能 以 数 据 表 形 式 显 示 参 数, 并 可 选 配 控 制 软 件 LSC-8 1/4 VGA 大 屏 幕

More information

WinMDI 28

WinMDI 28 WinMDI WinMDI 2 Region Gate Marker Quadrant Excel FACScan IBM-PC MO WinMDI WinMDI IBM-PC Dr. Joseph Trotter the Scripps Research Institute WinMDI HP PC WinMDI WinMDI PC MS WORD, PowerPoint, Excel, LOTUS

More information

Chapter 2

Chapter 2 2 (Setup) ETAP PowerStation ETAP ETAP PowerStation PowerStation PowerPlot ODBC SQL Server Oracle SQL Server Oracle Windows SQL Server Oracle PowerStation PowerStation PowerStation PowerStation ETAP PowerStation

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

PTS7_Manual.PDF

PTS7_Manual.PDF User Manual Soliton Technologies CO., LTD www.soliton.com.tw - PCI V2.2. - PCI 32-bit / 33MHz * 2 - Zero Skew CLK Signal Generator. - (each Slot). -. - PCI. - Hot-Swap - DOS, Windows 98/2000/XP, Linux

More information

目 录

目 录 1 Quick51...1 1.1 SmartSOPC Quick51...1 1.2 Quick51...1 1.3 Quick51...2 2 Keil C51 Quick51...4 2.1 Keil C51...4 2.2 Keil C51...4 2.3 1 Keil C51...4 2.4 Flash Magic...9 2.5 ISP...9 2.6...10 2.7 Keil C51...12

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

ebook140-9

ebook140-9 9 VPN VPN Novell BorderManager Windows NT PPTP V P N L A V P N V N P I n t e r n e t V P N 9.1 V P N Windows 98 Windows PPTP VPN Novell BorderManager T M I P s e c Wi n d o w s I n t e r n e t I S P I

More information

计算机网络编程

计算机网络编程 计算机网络编程 第 2 章 Socket 编程基础知识 信息工程学院方徽星 fanghuixing@hotmail.com 本章主要内容 Socket 编程的基本概念 Winsock 网络编程接口 2.1 Socket 编程的基本概念 套接字 (Socket): 网络层的 IP 地址 + 传输层的端口号 客户机 服务器 应用进程 通信子网 应用进程 客户机 Socket 请求 服务器 Socket

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

INTRODUCTION TO COM.DOC

INTRODUCTION TO COM.DOC How About COM & ActiveX Control With Visual C++ 6.0 Author: Curtis CHOU mahler@ms16.hinet.net This document can be freely release and distribute without modify. ACTIVEX CONTROLS... 3 ACTIVEX... 3 MFC ACTIVEX

More information

图 4.2 udpclient 项目解决方案 3. 客户机程序编码如下 : 程序 : udp 客户机程序 udpclient.cpp

图 4.2 udpclient 项目解决方案 3. 客户机程序编码如下 : 程序 : udp 客户机程序 udpclient.cpp 实验四 UDP 客户机和服务器设计 一 实验目的 1. 学习和理解 UDP 协议 ( 对照 TCP 协议 ) 2. 掌握 UDP 客户机与服务器程序的设计方法 3. 掌握 UDP 套接字创建方法, 掌握 sendto recvfrom 等函数用法 注意与 send recv 函数做对比性学习 二 实验内容 1. 完成发送和接收数据报的客户机设计 2. 完成接收和回送数据报的服务器设计 3.( 选做

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

Socket Socket TcpClient Socket.Connect TcpClient.Connect Socket.Send / Receive NetworkStream 6-5

Socket Socket TcpClient Socket.Connect TcpClient.Connect Socket.Send / Receive NetworkStream 6-5 6 6-1 6-2 Socket 6-2-1 Socket 6-2-2 TcpClient 6-3 6-3-1 Socket.Connect 6-3-2 TcpClient.Connect 6-4 6-4-1 Socket.Send / Receive 6-4-2 NetworkStream 6-5 6-5-1 Socket.Close 6-5-2 TcpClient.Close 6-6 DateTime

More information

Microsoft Word - 第3章.doc

Microsoft Word - 第3章.doc Java C++ Pascal C# C# if if if for while do while foreach while do while C# 3.1.1 ; 3-1 ischeck Test() While ischeck while static bool ischeck = true; public static void Test() while (ischeck) ; ischeck

More information

软件测试(TA07)第一学期考试

软件测试(TA07)第一学期考试 一 判 断 题 ( 每 题 1 分, 正 确 的, 错 误 的,20 道 ) 1. 软 件 测 试 按 照 测 试 过 程 分 类 为 黑 盒 白 盒 测 试 ( ) 2. 在 设 计 测 试 用 例 时, 应 包 括 合 理 的 输 入 条 件 和 不 合 理 的 输 入 条 件 ( ) 3. 集 成 测 试 计 划 在 需 求 分 析 阶 段 末 提 交 ( ) 4. 单 元 测 试 属 于 动

More information

提纲 1 2 OS Examples for 3

提纲 1 2 OS Examples for 3 第 4 章 Threads2( 线程 2) 中国科学技术大学计算机学院 October 28, 2009 提纲 1 2 OS Examples for 3 Outline 1 2 OS Examples for 3 Windows XP Threads I An Windows XP application runs as a seperate process, and each process may

More information

Microsoft Word - PS2_linux_guide_cn.doc

Microsoft Word - PS2_linux_guide_cn.doc Linux For $ONY PlayStatioin2 Unofficall General Guide Language: Simplified Chinese First Write By Beter Hans v0.1 Mail: hansb@citiz.net Version: 0.1 本 人 是 菜 鸟 + 小 白 欢 迎 指 正 错 误 之 处, 如 果 您 有 其 他 使 用 心 得

More information

els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8

els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8 els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8 Yamaha ELS-0/0C..8 LCD ELS-0/0C v. typeu LCD ELS-0/0C typeu / -6 / [SEARCH] / - ZH ELS-0/0C.8 els0xu_zh_nf_v8.book Page Wednesday, June,

More information

Linux网络编程socket错误分析

Linux网络编程socket错误分析 Linux 网 络 编 程 socket 错 误 分 析 socket 错 误 码 : EINTR: 4 阻 塞 的 操 作 被 取 消 阻 塞 的 调 用 打 断 如 设 置 了 发 送 接 收 超 时, 就 会 遇 到 这 种 错 误 只 能 针 对 阻 塞 模 式 的 socket 读, 写 阻 塞 的 socket 时,-1 返 回, 错 误 号 为 INTR 另 外, 如 果 出 现 EINTR

More information

1 o o o CPU o o o o o SQL Server 2005 o CPU o o o o o SQL Server o Microsoft SQL Server 2005

1 o o o CPU o o o o o SQL Server 2005 o CPU o o o o o SQL Server o Microsoft SQL Server 2005 1 o o o CPU o o o o o SQL Server 2005 o CPU o o o o o SQL Server o Microsoft SQL Server 2005 1 1...3 2...20 3...28 4...41 5 Windows SQL Server...47 Microsoft SQL Server 2005 DBSRV1 Microsoft SQL Server

More information

Data Server_new_.doc

Data Server_new_.doc 0i B/C Data Server Windows 2000 Window XP Windows XP FTP FANUC Data Server FTP liwei@beijing-fanuc 1 06-10-8 Content 1. /...3 1.1...3 1.2...3 1.3 CNC...3 2....5 2.1 STORAGE...5 2.2 FTP...6 2.3 BUFFER...7

More information

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2 PowerBuilder 9 PowerBuilder Native Interface(PBNI) PowerBuilder 9 PowerBuilder C++ Java PowerBuilder 9 PBNI PowerBuilder Java C++ PowerBuilder NVO / PowerBuilder C/C++ PowerBuilder 9.0 PowerBuilder Native

More information

计算机网络实验

计算机网络实验 计算机网络课程设计 成绩评定 : 总评成绩 : 考勤 20%+ 提问 60%+ 课设报告 20% 2 选题方式 : 选题的题号 : 学号位数模 5+1: 比如 : 201503302 刘子豪同学的选题为 : 2%6+1=3 刘子豪同学的选题为第 3 题 3 题目 : 题目 1: 基于 TCP 协议的简易聊天机器人 题目 2: 基于 TCP 协议的通讯录 题目 3: 基于 UDP 协议的简易聊天机器人

More information

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile.. WebSphere Studio Application Developer IBM Portal Toolkit... 1/21 WebSphere Studio Application Developer IBM Portal Toolkit Portlet Doug Phillips (dougep@us.ibm.com),, IBM Developer Technical Support Center

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

¶C¶L§§¬_™¨ A.PDF

¶C¶L§§¬_™¨ A.PDF 1 9 3 1 9 4 / 7.1 / 1 9 5 7.2 % netstat -rn Routing tables Destination Gateway Flags Refcnt Use Interface 127.0.0.1 127.0.0.1 UH 1 132 lo0 172.16.12.0 172.16.12.2 U 26 49041 le0 1 9 6 / % ping -s almond

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

Windows XP

Windows XP Windows XP What is Windows XP Windows is an Operating System An Operating System is the program that controls the hardware of your computer, and gives you an interface that allows you and other programs

More information

財金資訊-80期.indd

財金資訊-80期.indd IPv6 / LINE YouTube TCP/IP TCP (Transmission Control Protocol) IP (Internet Protocol) (node) (address) IPv4 168.95.1.1 IPv4 1981 RFC 791 --IP IPv4 32 2 32 42 IP (Internet Service Provider ISP) IP IP IPv4

More information

Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice

Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice 路 ESW 聯 USB Chapter 9 Applications For Windows Outline USB Application Requirements Variable Definition Communications Code for VB Code for Keil C Practice USB I/O USB / USB 3 料 2 1 3 路 USB / 列 料 料 料 LED

More information

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2 Terminal Mode No User User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2 Mon1 Cam-- Mon- Cam-- Prohibited M04 Mon1 Cam03 Mon1 Cam03

More information

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f 27 1 Vol.27 No.1 CEMENTED CARBIDE 2010 2 Feb.2010!"!!!!"!!!!"!" doi:10.3969/j.issn.1003-7292.2010.01.011 OPC 1 1 2 1 (1., 412008; 2., 518052), OPC, WinCC VB,,, OPC ; ;VB ;WinCC Application of OPC Technology

More information

IP Access Lists IP Access Lists IP Access Lists

IP Access Lists IP Access Lists IP Access Lists Chapter 10 Access Lists IP Access Lists IP Access Lists IP Access Lists Security) IP Access Lists Access Lists (Network router For example, RouterA can use an access list to deny access from Network 4

More information

Chap6.ppt

Chap6.ppt Computer Networks v4 cs.sjtu 12/21/12 6 Internet ftp://ftp.cs.sjtu.edu.cn/ybzhang 61 / 110 Computer Networks v4 cs.sjtu 12/21/12 ftp://ftp.cs.sjtu.edu.cn/ybzhang 62 / 110 Computer Networks v4 cs.sjtu 12/21/12

More information

《 计 算 机 网 络 》

《 计 算 机 网 络 》 1 ... 5 1.1... 5 1.2... 5 1.3... 5 1.4... 6 BOSON NETSIM...11 2.1... 11 2.2... 11 2.3 BOSON NETSIM... 27 CISCO... 31 3.1... 31 3.2 IP... 33 3.3... 34... 36 4.1... 36 4.2... 41 4.3... 47 Socket 2 ... 50

More information

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor 1 4.1.1.1 (Load) 14 1.1 1 4.1.1.2 (Save) 14 1.1.1 1 4.1.2 (Buffer) 16 1.1.2 1 4.1.3 (Device) 16 1.1.3 1 4.1.3.1 (Select Device) 16 2 4.1.3.2 (Device Info) 16 2.1 2 4.1.3.3 (Adapter) 17 2.1.1 CD-ROM 2 4.1.4

More information

Olav Lundström MicroSCADA Pro Marketing & Sales 2005 ABB - 1-1MRS755673

Olav Lundström MicroSCADA Pro Marketing & Sales 2005 ABB - 1-1MRS755673 Olav Lundström MicroSCADA Pro Marketing & Sales 2005 ABB - 1 - Contents MicroSCADA Pro Portal Marketing and sales Ordering MicroSCADA Pro Partners Club 2005 ABB - 2 - MicroSCADA Pro - Portal Imagine that

More information

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP

TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP TCP/IP : TCP/IP TCP/IP OSI IP TCP IP IP TCP/IP TCP/IP 1. ASCII EBCDIC Extended Binary-Coded Decimal Interchange Code 2. / (1) (2) Single System Image SSI) (3) I/O (4) 3.OSI OSI Open System Interconnection

More information

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO Linux muduo C++ (giantchen@gmail.com) 2012-09-30 C++ TCP C++ x86-64 Linux TCP one loop per thread Linux native muduo C++ IT 5 C++ muduo 2 C++ C++ Primer 4 W. Richard Stevens UNIX Sockets API echo Sockets

More information

科学计算的语言-FORTRAN95

科学计算的语言-FORTRAN95 科 学 计 算 的 语 言 -FORTRAN95 目 录 第 一 篇 闲 话 第 1 章 目 的 是 计 算 第 2 章 FORTRAN95 如 何 描 述 计 算 第 3 章 FORTRAN 的 编 译 系 统 第 二 篇 计 算 的 叙 述 第 4 章 FORTRAN95 语 言 的 形 貌 第 5 章 准 备 数 据 第 6 章 构 造 数 据 第 7 章 声 明 数 据 第 8 章 构 造

More information

附录一 简明Socket编程指南

附录一 简明Socket编程指南 附录一简明 Socket 编程指南 在本说明文档中, 主要讲述了一些网络 SOCKET 编程的基本概念和有关函数说明, 并 给出了部分示例程序的源代码 在完成 TCP 和 IP 通信程序设计实验 实时声音传输实 验 和 HTTP 代理实现实验 时, 可以参考本文档的内容 一 SOCKET 基本概念 1 Linux/Unix:Socket 函数库 Linux Socket 函数库是从 Berkeley

More information

untitled

untitled 1 Outline 數 料 數 數 列 亂數 練 數 數 數 來 數 數 來 數 料 利 料 來 數 A-Z a-z _ () 不 數 0-9 數 不 數 SCHOOL School school 數 讀 school_name schoolname 易 不 C# my name 7_eleven B&Q new C# (1) public protected private params override

More information

ebook 185-6

ebook 185-6 6 Red Hat Linux DB2 Universal Database 6.1 D B 2 Red Hat D B 2 Control Center D B 2 D B 2 D B 2 6.1 DB2 Universal Database [DB2]6.1 D B 2 O LT P O L A P D B 2 I B M P C We e k D B 2 D B 2 L i n u x Windows

More information

* RRB *

* RRB * *9000000000RRB0010040* *9000000000RRB0020040* *9000000000RRB0030040* *9000000000RRB0040040* *9000000000RRC0010050* *9000000000RRC0020050* *9000000000RRC0030050* *9000000000RRC0040050* *9000000000RRC0050050*

More information

untitled

untitled 3 C++ 3.1 3.2 3.3 3.4 new delete 3.5 this 3.6 3.7 3.1 3.1 class struct union struct union C class C++ C++ 3.1 3.1 #include struct STRING { typedef char *CHARPTR; // CHARPTR s; // int strlen(

More information

自由軟體教學平台

自由軟體教學平台 NCHC Opensource task force Steven Shiau steven@nchc.gov.tw National Center for High-Performance Computing Sep 10, 2002 1 Outline 1. 2. 3. Service DHCP, TFTP, NFS, NIS 4. 5. 2 DRBL (diskless remote boot

More information