简体   繁体   中英

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. 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. I've read many things about WebClients and HttpWebRequest, but can't seem to succeed. One thing I've tried, but which is totally done randomly since I have no idea how to use the WebClient class:

   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...). 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 :)

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 :

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

but maybe better use FtpWebRequest

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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