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