HELP: Questions regarding setting up a network connection

Last post 03-31-2008, 2:13 AM by Gibby. 3 replies.
Sort Posts: Previous Next
  •  03-31-2008, 2:05 AM

    HELP: Questions regarding setting up a network connection

    I've initialized the following variables as shown in one of the online tutorials:

    Globals:

    NetworkSessionProperties sessionProperties;
    NetworkSession session;

    protected override void Initialize()
    {
    // TODO: Add your initialization logic here
    sessionProperties = new NetworkSessionProperties();
    sessionProperties[(int)SessionProperty.GameMode] = (int)GameMode.Practice; // Game mode
    sessionProperties[(int)SessionProperty.SkillLevel] = (int)SkillLevel.Beginner; // Score to win
    sessionProperties[(int)SessionProperty.ScoreToWin] = 100;

    // Create the session
    session = NetworkSession.Create(NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers, privateGamerSlots, sessionProperties);
    session.AllowHostMigration = true;
    session.AllowJoinInProgress = true;

    base.Initialize();
    }


    I've also added this line in the game's constructor: Components.Add(new GamerServicesComponent(this)); But why am I still getting this error when it tries to call NetworkSession.Create: + $exception {System.InvalidOperationException: The Gamer Services functionality must be initialized before you call this method. The easiest way to do that is to add a GamerServicesComponent to the Game.Components collection in the constructor of your Game class. at Microsoft.Xna.Framework.GamerServices.GamerServicesDispatcher.get_PacketBuffer() at Microsoft.Xna.Framework.Net.NetworkSession.BeginCreate(NetworkSessionType sessionType, Int32 maxLocalGamers, Int32 maxGamers, Int32 privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, Object asyncState) at Microsoft.Xna.Framework.Net.NetworkSession.Create(NetworkSessionType sessionType, Int32 maxLocalGamers, Int32 maxGamers, Int32 privateGamerSlots, NetworkSessionProperties sessionProperties) at NetworkDemo.Game1.Initialize() at Microsoft.Xna.Framework.Game.Run() at NetworkDemo.Program.Main(String[] args) } System.Exception {System.InvalidOperationException}
  •  03-31-2008, 2:07 AM

    Re: HELP: Questions regarding setting up a network connection

    The reason is that the GamerServicesComponent isn't initialized when you add it; it gets initialized when your game calls base.Initialize. Therefore if you move the base.Initialize above all of your network code there it should work just fine.


    Nick Gravelyn -- Microsoft XNA MVP
    XNA Wiki | Zune Games
  •  03-31-2008, 2:11 AM

    Re: HELP: Questions regarding setting up a network connection

    AH! Hrm...did not know that! I don't think I read any of that anywhere in the tutorial. I'll try that now!
  •  03-31-2008, 2:13 AM

    Re: HELP: Questions regarding setting up a network connection

    Awesome! Thanks for the help! :) Now I just have to figure out what to do with it now...hehe.
View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback