在c#.net中如何通过互联网向远程计算机发送消息?
c#.net Framework 4.0 客户端配置文件,Windows 应用程序.. 我正在开发一款游戏,需要通过互联网将游戏的当前动作发送到安装了相同应用程序(游戏)的远程计算机。以同样的方式,远程计算机游戏的当前动作应该被发送回... 这怎么可能?
c#.net framework 4.0 client profile,Windows application..
i am developing a game which needs to send its current movements of the game through internet to remote computer where the same application(game) is installed.In Same way current movements of the game of remote computer should be send back...
How this could be possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
到目前为止,所有答案都使用基于 TCP 的方法。如果您需要高性能和低延迟,那么您可能会发现使用 UDP 更好。
TCP 带来了大量的开销,以保证数据包在丢失时将被重新发送(以及各种其他功能)。另一方面,UDP 让您自行处理未到达的数据包。如果您的游戏中丢失奇怪的更新并不重要,您可以通过使用 UDP 而不是 TCP 来实现更好的带宽使用、延迟和可扩展性。
尽管如此,UDP 仍然会给您带来防火墙、安全等所有问题。
如果您需要让它正常工作而不用担心防火墙问题,那么您需要选择通过端口 80 使用 HTTP 的解决方案。
All the answers so far are using a TCP based approach. If you need high performance and low latency then you might find it better to use UDP instead.
TCP brings a lot of overhead with it to guarantee that packets will be resent if they are lost (and various other bits of functionality). UDP on the other hand leaves it up to you to deal with packets not arriving. If you have a game where losing the odd update isn't important you can achieve far better bandwidth use, latency and scalability by using UDP instead of TCP.
UDP still leaves you with all the issues of firewalls, security etc though.
If you need to have it work without worrying about firewalls being an issue then you want to choose a solution that uses HTTP over port 80.
为此,您需要通过 TCP/IP 实现客户端-服务器行为
有多种不同的方法可以做到这一点
我编写的这段代码可以为您提供一个开始(这是一种选择,但不是唯一的选择,我让您选择最适合您的方法)
希望这会有所帮助。
To do that you need to implement a client-server behavior through TCP/IP
There are very different ways to do this
This code I've written could give you a start (it's an option, but not the only one, I leave it off to you to choose the method that suits you best)
Hope this Helps.
您应该研究一些中间件技术,例如 WCF、网络服务
这是面向对象的,当你第一次掌握它时很容易开发
You should look into some middleware teknologies like WCF, Web service
this is object oriented and easy to develop when you first get the hang of it
为此你需要考虑很多。
您需要考虑
安全
、防火墙问题
等。如果这些都放在一边,那么您可以设置 tcp 套接字服务器/客户端方法。
快速谷歌一下就会得到很多例子。
查看 Microsoft 示例 http://msdn.microsoft。 com/en-us/library/system.net.sockets.socket.aspx
您尝试过什么?
You have a lot to consider for this.
You will need to think about
security
,firewall issues
etc.If that is all put to one side, then you can set up a tcp socket server / client approach.
A quick google will yield plenty of examples.
Check out the Microsoft example http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
What have you tried?
您可以使用 System.Net 和 System.Net.Sockets 命名空间发送 TCP 数据包。
You can use the System.Net and System.Net.Sockets namespaces to send TCP packets.