首页 | 中文黄页 | 2008卡拉OK大赛

渥太华华人网上社区
注册账号 Blog 论坛帮助 会员列表 搜索 今日新帖 标记版面已读 用户相册
返回   CFC加拿大中文论坛 > 加国生活 > 渥太华华人论坛 > 请教:如何将一个socket和一个文件handle联系起来?
回复
 
主题工具 显示模式
[中级会员]
ID: 6834
nova 的头像
nova 是普普通通的会员
声望: 0 声望力: 0
帖子: 235
家族:
来自:
金钱: 2,796
注册: 2003-04-20
请教:如何将一个socket和一个文件handle联系起来?

请教高手:在windows 环境下如何将一个socket和一个文件handle联系起来?在Unix 和Linux中很容易用FILE *fp = fdopen ((SOCKET)sockid, "r"); 但windows (VC++6.0)似乎不能用一个文件打开一个TCP连接。
nova 当前离线  
回复时引用此帖
旧 2003-10-07, 17:04 #1
[青铜长老]
ID: 350
chengchy 的头像
chengchy 是普普通通的会员
声望: 0 声望力: 0
帖子: 1,245
家族:
来自:
金钱: 2,680
注册: 2002-02-14

windows API没有那么不堪。MSDN都给你封装好了。看看CSocketFile这个class吧。
chengchy 当前离线  
回复时引用此帖
旧 2003-10-07, 17:46 #2
[中级会员]
ID: 6834
nova 的头像
nova 是普普通通的会员
声望: 0 声望力: 0
帖子: 235
家族:
来自:
金钱: 2,796
注册: 2003-04-20

多谢chengchy。问题是我们现在在WINDOWS环境中仿真程序(GUI,IO等仿真是在WINDOWS下的)。等硬件来了后要移植到一种类似LINUX的操作系统中。因此得用低级socket 和file函数。有没有其它办法?
nova 当前离线  
回复时引用此帖
旧 2003-10-07, 17:57 #3
[青铜长老]
ID: 350
chengchy 的头像
chengchy 是普普通通的会员
声望: 0 声望力: 0
帖子: 1,245
家族:
来自:
金钱: 2,680
注册: 2002-02-14

If you can not use MFC classes and would like to make those things more portable, try using _fdopen. This IS supported in Windows api. But still, when you port this piece code to LINUX, make sure modify the code.

You can do like this in the header file:
#define _fdopen fdopen

OR

You can modify your makefile and pass in pre-compiler options when on LINUX. likely say -DLINUX

then in the code, you can write:
#ifdefine LINUX
fdopen(.....)
#elif
_fdopen(....)
#endif
chengchy 当前离线  
回复时引用此帖
旧 2003-10-07, 18:32 #4
[中级会员]
ID: 6834
nova 的头像
nova 是普普通通的会员
声望: 0 声望力: 0
帖子: 235
家族:
来自:
金钱: 2,796
注册: 2003-04-20

thanks again chengchy! I tried and it does not work. It gives me the same error as using fdopen(). The problem is that in windows, the socket handle is different from the file handle. While in all other major OS, they are same. I will take your suggestion to try to wrap CSocketFile with directive definitions.

thanks,

Nova
nova 当前离线  
回复时引用此帖
旧 2003-10-07, 18:53 #5
回复


主题工具
显示模式




所有时间均为格林尼治时间 -4。现在的时间是 05:06

论坛内容均为网友自由上传, 不代表本网观点。
comefromchina.com does not represent or guarantee the truthfulness, accuracy, or reliability of any of communications posted by other users.


Powered by vBulletin® 版本 3.6.8
版权所有 ©2000 - 2008,Jelsoft Enterprises Ltd.
Copyright @ comefromchina.com 2007

SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.