c#.net框架4.0客户端配置文件,Windows应用程序..我正在开发一个游戏,需要通过互联网发送其当前的游戏运动到远程计算机,在那里相同的应用程序(游戏)是installed.In相同的方式远程计算机的游戏的当前运动应该发送回...这怎么可能呢?
发布于 2010-12-02 18:43:58
到目前为止,所有的答案都是使用基于TCP的方法。如果您需要高性能和低延迟,那么您可能会发现使用UDP会更好。
TCP带来了大量开销,以保证数据包在丢失时将被重新发送(以及其他各种功能)。另一方面,UDP让您来处理未到达的数据包。如果你有一个游戏,丢失奇怪的更新并不重要,你可以通过使用UDP而不是TCP来实现更好的带宽使用、延迟和可伸缩性。
尽管如此,UDP仍然给你留下了所有的防火墙,安全等问题。
如果您需要在不担心防火墙问题的情况下让它工作,那么您需要选择一个使用HTTP而不是端口80的解决方案。
发布于 2010-12-02 18:34:56
为此,您需要通过TCP/IP实现客户端-服务器行为
有很多不同的方法可以做到这一点我写的代码可以给你一个开始(这是一个选择,但不是唯一的,我让你选择最适合你的方法)
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
static class ServerProgram
{
[STAThread]
static void Main()
{
ATSServer();
}
static void ATSServer()
{
TcpChannel tcpChannel = new TcpChannel(7000);
ChannelServices.RegisterChannel(tcpChannel);
Type commonInterfaceType = Type.GetType("ATSRemoteControl");
RemotingConfiguration.RegisterWellKnownServiceType(commonInterfaceType,
"RemoteATSServer", WellKnownObjectMode.SingleCall);
}
}
public interface ATSRemoteControlInterface
{
string yourRemoteMethod(string parameter);
}
public class ATSRemoteControl : MarshalByRefObject, ATSRemoteControlInterface
{
public string yourRemoteMethod(string GamerMovementParameter)
{
string returnStatus = "GAME MOVEMENT LAUNCHED";
Console.WriteLine("Enquiry for {0}", GamerMovementParameter);
Console.WriteLine("Sending back status: {0}", returnStatus);
return returnStatus;
}
}
class ATSLauncherClient
{
static ATSRemoteControlInterface remoteObject;
public static void RegisterServerConnection()
{
TcpChannel tcpChannel = new TcpChannel();
ChannelServices.RegisterChannel(tcpChannel);
Type requiredType = typeof(ATSRemoteControlInterface);
//HERE YOU ADJUST THE REMOTE TCP/IP ADDRESS
//IMPLEMENT RETRIEVAL PROGRAMATICALLY RATHER THAN HARDCODING
remoteObject = (ATSRemoteControlInterface)Activator.GetObject(requiredType,
"tcp://localhost:7000/RemoteATSServer");
string s = "";
s = remoteObject.yourRemoteMethod("GamerMovement");
}
public static void Launch(String GamerMovementParameter)
{
remoteObject.yourRemoteMethod(GamerMovementParameter);
}
}
希望这能有所帮助。
发布于 2010-12-02 18:28:30
您应该研究一些中间件技术,如WCF、Web service。这是面向对象的,当您刚掌握它时,它很容易开发。
https://stackoverflow.com/questions/4333803
复制相似问题