简体   繁体   English

在线写作/阅读文字

[英]Writing/Reading text online

The title is rather inexplicit, but that's because I'm open to almost any suggestions. 标题不太明确,但这是因为我愿意接受任何建议。 Actually, I'm working on an XNA game project and I am working on implementing the possibility to choose a multiplayer game from a list of name. 实际上,我正在开发XNA游戏项目,并且正在实现从名称列表中选择多人游戏的可能性。 Typically, the datas I want to send should be a string of that kind : 通常,我要发送的数据应该是该类型的字符串:

   "ServerName;00.00.000.000"

For what I know, that can only be possible with a dedicated server (which is not an option I can consider) or by recording datas online somewhere it can be read by any clients. 据我所知,这只能通过专用服务器(这不是我可以考虑的选项)或通过在线记录数据的方式来实现,该数据可以被任何客户端读取。 I've studied several possibilities but I only came up with failures. 我研究了几种可能性,但我只想到失败。 My first idea (and the ideal one) would be to – with a C# method – send datas to my website. 我的第一个想法(也是理想的想法)是-使用C#方法-将数据发送到我的网站。 I've read many things about WebClients and HttpWebRequest, but can't seem to succeed. 我已经阅读了许多有关WebClients和HttpWebRequest的内容,但似乎无法成功。 One thing I've tried, but which is totally done randomly since I have no idea how to use the WebClient class: 我尝试过的一件事,但是由于我不知道如何使用WebClient类,因此完全是随机完成的:

   WebClient client = new WebClient();
   client.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
   using (StreamWriter writer = new StreamWriter(client.OpenWrite(@"http://www.myawsomewebsite/test.html")))
        {
            writer.WriteLine("COUCOU");
            writer.Flush();
        }

If you want this communication with server to be efficiend and fast you will need some sort of server side code (ASP.NET, PHP...). 如果您希望与服务器之间的这种通信高效且快速,则需要某种服务器端代码(ASP.NET,PHP ...)。 There is a ton of open source code and examples for PHP or ASP.NET to achieve this communication, maybe you event find product that you can use without any changes, so please do your googling :) 有大量用于PHP或ASP.NET的开源代码和示例可实现此通信,也许您发现了可以直接使用的产品,因此请进行谷歌搜索:)

btw. 顺便说一句 if you still want to stick with WebClient.OpenWrite only then you can write to files trough FTP protocol, documentation for OpenWrite said it's supported : 如果您仍然只想使用WebClient.OpenWrite则可以通过FTP协议写入文件,OpenWrite的文档说它受支持:

http://msdn.microsoft.com/en-us/library/0a7f52z4.aspx http://msdn.microsoft.com/en-us/library/0a7f52z4.aspx

but maybe better use FtpWebRequest 但也许最好使用FtpWebRequest

http://msdn.microsoft.com/en-us/library/ms144318.aspx http://msdn.microsoft.com/en-us/library/ms144318.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM