7 Replies - 1791 Views - Last Post: 17 November 2012 - 08:57 AM

#1 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

How can I create a multiplayer game?

Posted 10 November 2012 - 05:48 AM

Hi, I'm going to briefly outline what I require to make this post easier to understand:

- Tutorial in XNA 4.0, not 3.1, 3.0 or 2.0, I won't know what needs changing
- Tutorial that doesn't overwhelm, I need to learn the basics before drawing lobbies and more, the key principles behind XNA's net programming

The reason I am so specific with these requirements is because I've spent the last hour searching the internet for a decent tutorial and can't seem to find any.

I did find these two tutorials:
http://msdn.microsof...).aspx#ID4EOEAE
This first tutorial proved too confusing, so much code and it's written in XNA 3.1

http://geekswithblog...networking.aspx
The second tutorial was a huge improvement, simple and to the point, and in XNA 4.0, but it seems like it was missing content. For example, there is an "isReady" if statement in there but there is no where in the tutorial where we define whether the player is ready or not.

I'd really appreciate if anyone could help me out!

Thanks,
Joel

Is This A Good Question/Topic? 0
  • +

Replies To: How can I create a multiplayer game?

#2 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2506
  • View blog
  • Posts: 4,615
  • Joined: 24-September 10

Re: How can I create a multiplayer game?

Posted 10 November 2012 - 07:06 AM

'IsEveryoneReady' is a member of the NetworkSession class:

http://msdn.microsof...on_members.aspx



1) work on your google-fu if you can't find tutorials
2) don't basically come and ask us to do your googling for you
3) we're not going to write tutorials for you (well BBeck might with their long ass posts... heh :P)
4) always check MSDN to reference any tutorial against, so you understand the interface of the classes that are used in said tutorials (or code samples, or just in general... MSDN IS your reference material)
Was This Post Helpful? 2
  • +
  • -

#3 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 535
  • View blog
  • Posts: 1,191
  • Joined: 24-April 12

Re: How can I create a multiplayer game?

Posted 10 November 2012 - 07:08 AM

I'm not certain it's possible to do a networked game in XNA. I believe it is, but I haven't tried it and I've heard people say it's not possible. I think I've seen some stuff in some of the XNA books on going through Microsoft's Live network for XNA games. I also suspect .Net's networking classes will work in XNA. But again, I've never tried to do that.

The last time I wrote network software I did it the "hard way". I did it in C++ and wrote a client and a server. It allowed multiple clients to connect to the server and communicate with one another through the server. Explaining how networking works at the lowest software level (TCP/IP) might help you understand.

Basically, TCP in IP is like a phone connection. You call into a TCP port (socket) and if the port is in listening mode it will answer and establish communications until one side or the other hangs up. As long as that channel is open between the sending port and the receiving port, what you have is just a byte stream. Anything you put in the send buffer is guaranteed to show up in the receiving buffer on the other end in the same order.

In Windows you can use a special Windows Asyncronis option that sets up a bunch of stuff up for you in the Windows loop. Doing that, here's how it works:

The server opens up a "listening" port on it's IP address(every network card in the machine can have a different IP address). That listening port just sits around and waits for someone to call in. If someone does, it tells them "Hey! Call me back on this other port over here." and then it hangs up on them. By hanging up, it's ready to listen for someone else to call in. The client makes the call into the listening port and then calls back on the port assigned by the listener. Once the server answers on the assigned port you have permenant communication established between the client and the server until one of them hangs up or the network crashes.

At that point, there is a send buffer and a receive buffer established for both sides. A Windows event will occur when something comes in on the receive buffer and you write an event handler to process whatever comes in on the receive buffer. When you put something on the send buffer, you raise an event for Windows to tell it that there's something on the send buffer that needs to be sent.

But WHATEVER you put on the send buffer, will show up on the other end in the receive buffer. It's just a byte stream. You could send plain English like "Give me a file named MyFile.", or more likely you would encode things into byte values that have agreed upon meanings between client and server.

A good starting project is to write your own Telnet client. Telnet is an unbelievably simple terminal program that just establishes a TCP/IP connection. It puts whatever is sent to it on the screen and sends whatever is typed on the keyboard, no questions asked. You can Telnet into any TCP/IP server. You can test by Telneting into a webserver. I think webpages are typically on port 80 as a listening port. In Telnet, you should see all the text of the webpage come up (the HTML code). You can also Telnet into an FTP server and send and receive files through Telnet IF you know how the FTP protocol works.

But the bottom line is that it's just a byte stream and you can program it to work anyway you want. Libary code, like .Net classes etc., could possibly work any way the programmer wants it to work. So, it's impossible to say how it works without knowledge of that specific libary code. But at the C++/Assembler/Machine Code/TCP/IP level it's just a byte stream.

This is called "Windows Sockets". There's a DLL in Windows that is called for all the TCP/IP functionality. I "believe" it's Sockets.dll, if I recall correctly, but I haven't messed with it in years. I learned most of how to do it from this book:

http://www.amazon.co...ket+programming

It's a good book, even if slightly dated. It should still work for C++ programming, or Assembly programming, in Windows 7. I couldn't say if it would still work as a Windows 8 app.

So, I know that doesn't answer your question about how to do it in XNA, but maybe that will help you on your journey a bit. I haven't done networking in XNA, so unfortunately I can't help you there. Hopefully, someone else can post something on the specifics of XNA networking.
Was This Post Helpful? 1
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8375
  • View blog
  • Posts: 31,132
  • Joined: 12-June 08

Re: How can I create a multiplayer game?

Posted 10 November 2012 - 07:09 AM

It's a complex topic so there will be a learning curve. Also be ready to hit up the documentation on MSDN to explain classes and functions of said classes.

Example:

Quote

in XNA 4.0, but it seems like it was missing content. For example, there is an "isReady" if statement in there but there is no where in the tutorial where we define whether the player is ready or not.


'isReady' is baked into the NetworkSession's properties.

http://msdn.microsof...er.isready.aspx


http://msdn.microsof...on_members.aspx

http://msdn.microsof...y/bb975773.aspx
http://msdn.microsof...y/bb975961.aspx
http://msdn.microsof...y/bb975500.aspx
http://msdn.microsof...y/bb975256.aspx
Was This Post Helpful? 1
  • +
  • -

#5 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 535
  • View blog
  • Posts: 1,191
  • Joined: 24-April 12

Re: How can I create a multiplayer game?

Posted 10 November 2012 - 07:12 AM

View Postlordofduct, on 10 November 2012 - 08:06 AM, said:

3) we're not going to write tutorials for you (well BBeck might with their long ass posts... heh :P/>/>)


Like I say, "If the shoe fits, ya gotta wear it." Guess I'm gonna be wearing the "long ass post" shoe. lol

What can I say. Guilty as charged. :-)

This post has been edited by BBeck: 10 November 2012 - 07:12 AM

Was This Post Helpful? 0
  • +
  • -

#6 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

Re: How can I create a multiplayer game?

Posted 10 November 2012 - 12:17 PM

View Postmodi123_1, on 10 November 2012 - 07:09 AM, said:

It's a complex topic so there will be a learning curve. Also be ready to hit up the documentation on MSDN to explain classes and functions of said classes.

Example:

Quote

in XNA 4.0, but it seems like it was missing content. For example, there is an "isReady" if statement in there but there is no where in the tutorial where we define whether the player is ready or not.


'isReady' is baked into the NetworkSession's properties.

http://msdn.microsof...er.isready.aspx


http://msdn.microsof...on_members.aspx

http://msdn.microsof...y/bb975773.aspx
http://msdn.microsof...y/bb975961.aspx
http://msdn.microsof...y/bb975500.aspx
http://msdn.microsof...y/bb975256.aspx


Thanks for all the replies guys! But the quoted one in particular is amazing, I didn't know that section existed at msdn! Thanks so much!
Was This Post Helpful? 0
  • +
  • -

#7 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

Re: How can I create a multiplayer game?

Posted 11 November 2012 - 06:37 AM

Ok so after following the msdn links in modi's post, I have setup everything but come across an error in the join network code.

            AvailableNetworkSession availableSession =
                availableSessions[sessionIndex];



Error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Any help would be highly appreciated!
Was This Post Helpful? 0
  • +
  • -

#8 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: How can I create a multiplayer game?

Posted 17 November 2012 - 08:57 AM

View Postjskidd3, on 11 November 2012 - 06:37 AM, said:

Ok so after following the msdn links in modi's post, I have setup everything but come across an error in the join network code.

            AvailableNetworkSession availableSession =
                availableSessions[sessionIndex];



Error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Any help would be highly appreciated!


Without digging into the tutorials provided, I assume that's an array of "AvailableNetworkSession"s. Basically, sessionIndex is going out of range. If there are for example 5 items in the array, and your looking for item 6, then that is the problem you are getting.

Breakpoints are your friend. Step through and watch the relevant variables.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1