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

Reading multiple sessions un local network

Last post 7/1/2009 5:07 PM by Milkhouse. 6 replies.
  • 7/1/2009 4:07 AM

    Reading multiple sessions un local network


    Hello guys! I'm new to this networking on xna and i'm developing a windows game that uses system link network.

    In my "lobby" i have a list that shows any available session on the net, this means that if someone in the net creates a session would appear in everybodys list. I fill this list with the using(availableNetworkSessionCollection availableSessions=NetworkSession.Find(......)) statement took from PeerToPeerSample. I use this list beacuse i want a player select a session that he would like to join and join it.

    I also have on the lobby a menu to create a new session (so this one should appear in others lists). Here comes the problem. When i create a session on a machine, it gives me this Exception (when list refreshes):

    "Could not create object because a different session already exists. There can only be one NetworkSession or AvailableNetworkSessionCollection in use at a time. You must Dispose any previous session before creating a new one."

    Why is this?? I don't know why it throws me this exception, since i'm not creating another session.

    Can i accomplish what i want to do with XNA SystemLink?? if i can... can someone guide me?? Beacuse i'm a little lost!! :P

    Thanks!!

    Sorry about my english, i speak spanish :P
  • 7/1/2009 3:00 PM In reply to

    Re: Reading multiple sessions un local network

    This error means that you must somewhere be creating more than one NetworkSession object, either by NetworkSession.Create or NetworkSession.Join. Either you have more than one place in your code that is creating sessions, or you are calling this more than once in a row. Put a breakpoint in the debugger each place you create a session and you will see where and when these are being called.
    XNA Framework Developer - blog - homepage
  • 7/1/2009 3:49 PM In reply to

    Re: Reading multiple sessions un local network


    Thanks for the answer Shawn! I did what you told me. Let me show you:

    I have a public NetworkSession NetWorkSession{get; set;} on my lobby and 3 methods that uses NetworkSession class:

    1 - CreateSession(): this method creates a new session, i do this with NetWorkSession =NetworkSession.Create(....). This method is called when the user press the 'New Session' button.

    2 - JoinSession(): with this method you join a selected session shown on the list. This method is called when i click on the 'Join Session' button

    3 - FillSessionsList(): with this method i search for any session created on the local network using the using(available..... = NetworkSession.Find(...)). This method is called once per second to refresh the list.

    The problem is that after i create a new session and the property NetWorkSession has a value, when it enters again in the FindSessionsList() it throws me the exception.

    None of the methods are called simultaniously.

    Maybe i'm doing something wrong. If you want to i can post some of the code.

    Thanks again!!
  • 7/1/2009 3:55 PM In reply to

    Re: Reading multiple sessions un local network

    You have to shutdown your current NetworkSession (with NetworkSession.Dispose()) before calling NetworkSession.Find.
  • 7/1/2009 4:38 PM In reply to

    Re: Reading multiple sessions un local network


    Ok i've done this. But an error occurs when i call the NetWorkSession.Update() (so others can detect it). It tells me that NetWorkSession has been Disposed :S

    I explain what i want to do:

    I have 4 PC's connected to a LAN. Everybody log into the game and goes to the Lobby screen. Here you have a list were you have sessions that someone in the LAN created. i.e.: 2 players created two sessions and the other two players can select from that list and join the session and play 1v1

    I want that list displayed on every player on the LAN. So what can i do (if i created a session) that in that list displays my session and others created??

    Can it be done?? Beacuse if i  can't i must redisign my lobby or something else

    Thanks!!
  • 7/1/2009 4:41 PM In reply to

    Re: Reading multiple sessions un local network

    Ok, I understand what you are saying now.

    And no, you can't do this. You can only have one session at a time. You must dispose whatever session you are currently using before you can search or join other sessions.
    XNA Framework Developer - blog - homepage
  • 7/1/2009 5:07 PM In reply to

    Re: Reading multiple sessions un local network


    Ok thanks Shawn! I must redisign my idea :(

    Thanks for the help!! This was my first time posting on Creators Club :) and the feedback was great!! Thanks!
Page 1 of 1 (7 items) Previous Next