lantionzy

coding
posts - 10, comments - 39, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
@侠客西风
我也是个菜鸟,也正在一步步走。慢慢积累吧,网上牛人多,资源也多,加油!
@欲三更
这位大哥,你一定是个牛人,我的文章水平太低,以后多向你学习。
Kevin yu 在其博客中写了一个头文件专门处理winsock2.h的包含问题,名为winsock2i.h:(当使用PSDK时,需要手工定义一下USING_WIN_PSDK)

//
// winsock2i.h - Include winsock2.h safely.
//
// Copyleft 02/24/2005 by freefalcon
//
//
// When WIN32_LEAN_AND_MEAN is not defined and _WIN32_WINNT is LESS THAN 0x400,
// if we include winsock2.h AFTER windows.h or winsock.h, we get some compiling
// errors as following:
// winsock2.h(99) : error C2011: 'fd_set' : 'struct' type redefinition
//
// When WIN32_LEAN_AND_MEAN is not defined and _WIN32_WINNT is NOT LESS THAN 0x400,
// if we include winsock2.h BEFORE windows.h, we get some other compiling errors:
// mswsock.h(69) : error C2065: 'SOCKET' : undeclared identifier
//
// So, this file is used to help us to include winsock2.h safely, it should be
// placed before any other header files.
//

#ifndef _WINSOCK2API_

// Prevent inclusion of winsock.h
#ifdef _WINSOCKAPI_
#error Header winsock.h is included unexpectedly.
#endif

// NOTE: If you use Windows Platform SDK, you should enable following definition:
// #define USING_WIN_PSDK

#if !defined(WIN32_LEAN_AND_MEAN) && (_WIN32_WINNT >= 0x0400) && !defined(USING_WIN_PSDK)
#include <windows.h>
#else
#include <winsock2.h>
#endif

#endif//_WINSOCK2API_

流式套接字提供没有记录边界的数据流:可以是双向的字节流(应用程序是全双工:可以通过套接字同时传输和接收)。可依赖流传递有序的、不重复的数据。(“有序”指数据包按发送顺序送达。“不重复”指一个特定的数据包只能获取一次。)这能确保收到流消息,而流非常适合处理大量数据。
数据文报套接字支持双向数据流,此数据留不能保证按顺序和不重复送达。数据文报也不保证是可靠的;它们可能无法到达目的地。数据文报可能不按顺序到达并且可能会重复,但只要记录的大小没有超过接收端的内部大小限制,就会保持数据中的记录边界。您负责管理顺序和可靠性。(可靠性在局域网 [LAN] 上往往很好,但在广域网 [WAN] 如 Internet 上却不太好。)数据文报为“无连接”的,也就是不建立显式连接。可将数据文报消息发送到指定的套接字,然后从指定的套接字接收消息。

本文所述是针对windows xp应用程序,而且非XP系统没有WTSAPI32。
re: 泛型算法 lantionzy 2009-10-15 14:08
@淘宝导购
欢迎评论和交流
网上找了下,这里有篇总结。让程序只运行一个实例的四种方法:
http://blog.csdn.net/magictong/archive/2008/12/25/3603015.aspx
@tailorcai
哦,学习了。将CreateMutex第三个参数改成"Global\\MyApp.EXE")即可。
谢谢
@guest
可以说得详细点吗?