c#.net framework 4.0客户端配置文件,Windows应用程序.. 我正在开发一款游戏,需要通过互联网将其当前的游戏动作发送到安装了相同应用程序(游戏)的远程计算机。远程计算机的游戏应发回... 这可能是怎么可能的?在c#.net如何通过互联网发送消息到远程计算机?
2
A
回答
0
您有很多事情要考虑。
您将需要考虑security
,firewall issues
等
如果这将是放在一边,那么你就可以建立一个TCP套接字服务器/客户端的方式。 快速谷歌将产生大量的例子。
退房微软例子http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
你尝试过什么?
0
您可以使用System.Net和System.Net.Sockets名称空间来发送TCP数据包。
1
你应该看看一些中间件teknologies像WCF,Web service 这是面向对象的,易开发,当你第一次得到了它的窍门
2
要做到这一点,你需要实现通过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);
}
}
希望这有助于。
2
同意的解决方案,UDP可能是一个更好的选择。 – Matt 2010-12-02 13:06:31