XNA Creators Club Online
Page 1 of 1 (16 items)
Sort Posts: Previous Next

Writing a Windows Forms Dedicated Server?

Last post 10-20-2008 5:50 PM by owen777. 15 replies.
  • 09-28-2008 5:14 PM

    Writing a Windows Forms Dedicated Server?

    Hi,

    I was wondering, if you can make a dedicated server instead of a in-game server. So yo can see how many people are inside the server in a label like if there are 5 people in the server then it would show '5 / 16'. '16' is the max internet players. And instead of being in the server all the time watching what people write, you can view what they write inside a listBox. And you can leave the server running all day all night.

    How do you do this?

    I've tryed doing it my self, but it really confused me.

    Please Help!

    Regards,

    Owen.

  • 09-30-2008 6:52 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    if you are planning on running this server for windows players only then it is totally possible using TCP/IP.  if you are trying to write it for xbox then you are out of luck.  there are tons of client server applications out there and the source code to them.  i know because i just wrote a MassMultiplayer server for my game.  i used http://blog.paranoidferret.com/index.php/2007/10/30/csharp-tutorial-simple-threaded-tcp-server/ to get me started.  if you need any help let me know, i had a lot of fun making it and know it well.
  • 10-01-2008 6:27 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    hi,

    I dont understand embbeding the XNA Server ( Client / Server sample ) into a main forms. Do you do this or start a new XNA game and embed the TCP/IP code he gave us? i'am confused.

    Can you let me see your zip? or is it not for one of the other games? i want to make it for 'Client/Server Sample'

  • 10-01-2008 8:29 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    first off your server will not ever be playing a game so it can just be a windows form application.  just like in the example I linked above.  use it to send messages back and forth to players.  for the client side, its just as easy.  from your load content method just start a thread and paste the client code in there.  of course once you get it working, you are going to want to make classes that control your messages.  if i were you i would get the clent working in a windows form before attempting to paste it into xna.  its a lot easier to debug a windows form.  I started off with a windows form client and windows form server.
  • 10-02-2008 3:00 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    Who ever deleted that full code post... Thank you!.

    ---------------------------------------------------------------

    ok i did what you said:

    protected override void LoadContent()

    {

    spriteBatch = new SpriteBatch(GraphicsDevice);

    font = Content.Load<SpriteFont>("Font");

    TcpClient tcpClient = (TcpClient)client;

    NetworkStream clientStream = tcpClient.GetStream();

    byte[ message = new byte[4096];

    int bytesRead;

    while (true)

    {

    bytesRead = 0;

    try

     

    {

    //blocks until a client sends a message

     

    bytesRead = clientStream.Read(message, 0, 4096);

    }

    catch

     

    {

    //a socket error has occured

     

    break;

    }

    if (bytesRead == 0)

    {

    //the client has disconnected from the server

     

    break;

    }

    //message has successfully been received

     

    ASCIIEncoding encoder = new ASCIIEncoding();

    System.Diagnostics.Debug.WriteLine(

    encoder.GetString(message, 0, bytesRead));

    }

    tcpClient.Close();

    }

     

    That was the code on the page, accept from the void loadcontent.

    I get three errors. I tryed putting bool methods in but doesnt work.

    | Errors | -

     

    Error 1 The type or namespace name 'TcpClient' could not be found (are you missing a using directive or an assembly reference?) 

    Error 2 The type or namespace name 'TcpClient' could not be found (are you missing a using directive or an assembly reference?) 

    Error 3 The name 'client' does not exist in the current context 

    Error 4 The type or namespace name 'NetworkStream' could not be found (are you missing a using directive or an assembly reference?) 

    Error 5 The type or namespace name 'ASCIIEncoding' could not be found (are you missing a using directive or an assembly reference?) 

    Error 6 The type or namespace name 'ASCIIEncoding' could not be found (are you missing a using directive or an assembly reference?) 

  • 10-02-2008 7:26 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?


    cpyburn:
    if you are planning on running this server for windows players only then it is totally possible using TCP/IP.  if you are trying to write it for xbox then you are out of luck.  there are tons of client server applications out there and the source code to them.  i know because i just wrote a MassMultiplayer server for my game.  i used http://blog.paranoidferret.com/index.php/2007/10/30/csharp-tutorial-simple-threaded-tcp-server/ to get me started.  if you need any help let me know, i had a lot of fun making it and know it well.

    Can this be used with the RPG starter kit to make an online game?

  • 10-02-2008 7:29 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    pillowyVEXER:
    Can this be used with the RPG starter kit to make an online game?
    cpyburn:
    if you are planning on running this server for windows players only then it is totally possible using TCP/IP.  if you are trying to write it for xbox then you are out of luck.  there are tons of client server applications out there and the source code to them.  i know because i just wrote a MassMultiplayer server for my game.  i used http://blog.paranoidferret.com/index.php/2007/10/30/csharp-tutorial-simple-threaded-tcp-server/ to get me started.  if you need any help let me know, i had a lot of fun making it and know it well.

     

     

    That was Random. Cany you help me? thats why i posted this thread.

  • 10-03-2008 12:11 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    owen777:

    | Errors | -

     

    Error 1 The type or namespace name 'TcpClient' could not be found (are you missing a using directive or an assembly reference?) 

    Error 2 The type or namespace name 'TcpClient' could not be found (are you missing a using directive or an assembly reference?) 

    Error 3 The name 'client' does not exist in the current context 

    Error 4 The type or namespace name 'NetworkStream' could not be found (are you missing a using directive or an assembly reference?) 

    Error 5 The type or namespace name 'ASCIIEncoding' could not be found (are you missing a using directive or an assembly reference?) 

    Error 6 The type or namespace name 'ASCIIEncoding' could not be found (are you missing a using directive or an assembly reference?) 

    owen777:

    Who ever deleted that full code post... Thank you!.

    ---------------------------------------------------------------

     

    1. Add these lines to the beginning of your code (among your other using statements):

    using System.Text;
    using System.Net.Sockets;

    This will solve all errors (except 3).

    2. 'client' variable wasn't declared anywhere in your code.

    You have to declare it as seen in the example:

    TcpClient client = this.tcpListener.AcceptTcpClient();

     

    I'm not sure why LoadContent method would be the correct place to put all this code, but that is a different question.

    Lior.

  • 10-04-2008 10:16 AM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    hi,

    Your right! it only leaves me with only 1 error with client. I've tryed adding a bool method again to it but i get know luck.

    Regards

    Owen.

  • 10-04-2008 11:00 AM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    TcpClient client = this.tcpListener.AcceptTcpClient();

    what do i do with that?

  • 10-07-2008 4:24 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    pillowyVEXER:

    cpyburn:
    if you are planning on running this server for windows players only then it is totally possible using TCP/IP.  if you are trying to write it for xbox then you are out of luck.  there are tons of client server applications out there and the source code to them.  i know because i just wrote a MassMultiplayer server for my game.  i used http://blog.paranoidferret.com/index.php/2007/10/30/csharp-tutorial-simple-threaded-tcp-server/ to get me started.  if you need any help let me know, i had a lot of fun making it and know it well.

    Can this be used with the RPG starter kit to make an online game?

    yes it can, it can be used with anything to make anything online.  it shows you how to make a server and a client and how to send a message.  once you know how to send a simple message you can send anything, like health points, mana, enemy locations, other player positions, etc.  One thing it doesnt show is how to turn a class seralizable so that it can be turned into bytes and sent as a message.  If you need help with that, start another thread and I will help you.

    And 777 Sorry I have been away for a bit. It scares me that you didnt know you needed to add the using statements... You probably dont understand threading either? First off you need to get it working in windows forms applications before you ever attempt putting it in XNA. XNA has no user interface and it will be very hard for you to see it working. Also you need to have the server running, before you attempt to connect with the client.  You need to have your firewall off cause it will block connection.  And there are 100 other things that could go wrong.  I tell you what, I will put the client and server application on the web for you to download in the next couple of days for you to test and try out.  There are a ton of concepts in the example you need to understand and I think you are jumping ahead of yourself trying to make a game online, but I am always willing to help someone willing to learn.   anyways, i will be back when i have it on my server for download.

  • 10-07-2008 4:43 PM In reply to

    Re: Writing a Windows Forms Dedicated Server?

    Hi, Cyburn

    Thx for the post! I went away and tested my self on how much do i know about programming so i made a game. These are the results i can do.

    1. Draw Sprites onto the screen
    2. Get them moving with keys
    ----------------------

    btw, will the Source code be on your server to for download? so i can see my mistakes? and what i needed to do in future?