本文以对照方式阐释了服务器套接字和客户端套接字的操作顺序。因为这些套接字使用 carchive 对象,所以它们必然是流式套接字。流式套接字通信的操作顺序
在构造 csocketfile 对象之前,下面的顺序对 casyncsocket 和 csocket 都是准确的(只有少数几个参数不同)。从构造 csocketfile 对象开始,顺序只适用于 csocket 。下表阐释了在客户端和服务器之间设置通信的操作顺序。 设置服务器和客户端之间的通信| 服务器 | 客户端 |
|---|---|
| // construct a socket csocket socksrvr; | // construct a socket csocket sockclient; |
| // create the socket socksrvr.create(nport); 1,2 | // create the socket sockclient.create( ); 2 |
| // start listening socksrvr.listen( ); | |
| // seek a connection sockclient.connect(straddr, nport); 3,4 | |
| // construct a new, empty socket csocket sockrecv; // accept connection socksrvr.accept( sockrecv ); 5 | |
| // construct file object csocketfile file(&sockrecv); | // construct file object csocketfile file(&sockclient); |
| // construct an archive carchive arin(&file, - 或 - carchive arout(&file, - 或两者 - | // construct an archive carchive arin(&file, - 或 - carchive arout(&file, - 或两者 - |
| // use the archive to pass data: arin >>dwvalue; - 或 - arout < < dwvalue; 6 | // use the archive to pass data: arin >>dwvalue; - 或 - arout < < dwvalue; 6 |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器