如何使用套接字在MFC中一次将文件从服务器发送到多个客户端? [英] How to send file from server to multiple clients at a time in mfc using sockets ?

查看:558
本文介绍了如何使用套接字在MFC中一次将文件从服务器发送到多个客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务器端做一个简单的&一个客户端应用程序,用于将文件从一个位置传输到另一位置,或者如果计算机在网络中,则从一台计算机传输到另一台计算机.

我使用了http://www.codeproject.com/KB/IP/SocketFileTransfer.aspx中的代码.它正在工作文件已成功传输.

但是我需要一次将文件从服务器传输到多个客户端.我的意思是在服务器上,应该有两个以上的客户端可以连接&他们可以同时接收文件.

我不知道如何为该&如何使用Threading&将 CSocket 对象传递给方法任何其他方式.

我也不知道如何准备 CSocket 对象的队列.

因此,如果您有任何解决方案或替代方法,请告诉我....

I am making simple one on server side & one on client side application for transferring file from one location to another location or from one computer to another computer if computers are in network.

I used the code from http://www.codeproject.com/KB/IP/SocketFileTransfer.aspx. It is working & file transferred successfully.

But i need to transfer file from server to multiple clients at a time. I mean on server, there should be more than two client can connect & they can receive file at same time.

I don''t know how to maintain queue for that & how to pass CSocket object to method using Threading & any other way.

I also don''t know how to prepare queue of CSocket objects.

So, please if you have any solution or alternative way then please tell me....

推荐答案

您可能想使用多播套接字,该套接字将发送数据同时向任何客户发送.

我本人还没有做任何事情,但是以下一些链接可能对您有用:

用于设置多播套接字的包装程序类此处 [此处 [ ^ ]
You may want to use a multicast socket, which would send the data simultaneously to any clients.

I''ve not done anything with it myself, but here are some links that you may find useful:

Wrapper Class for setting up a multicast socket here[^]

MSDN Pages on the subject, including example code here[^]


此处还有其他一些有关CodeProject的文章,这些文章可能会有所帮助:

-可重用的高性能套接字服务器类-第1部分 [异步套接字通信 [带有HTTP服务器示例的多线程服务器类 [ CAsyncSocket [ ^ ].
Here are some more CodeProject articles with alternatives that might help:

- A reusable, high performance, socket server class - Part 1[^]
- Asynchronous socket communication[^]
- Multithreaded server class with example of HTTP server[^]

With these examples you can choose between single threaded (asynchronous) and multi threaded networking. Generally, I would not use MFC''s CSocket class, it''s known to be unreliable and inefficient. When doing file transfer in the LAN, you probably want to use something fast to serve multiple clients. If you need to use MFC, check CAsyncSocket[^].


请参阅下面的链接,这必定会帮助您实现目标

具有多个客户端的单个服务器:简单的C ++实现 [
See this below link, this will assists you surely to serve your purpose

Single Server With Multiple Clients : a Simple C++ Implementation[^]


这篇关于如何使用套接字在MFC中一次将文件从服务器发送到多个客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆