|
-
Mar 7th, 2009, 05:36 PM
#1
Thread Starter
Hyperactive Member
[2008] Sending Variables via network
Im really new to .net, Ive got the basics to a game down, I need to be able to send variable arrays between programs, im aiming for local network first, then il tackle internet. Does .net have any simple way of doing this? Was a huge pain in vb 6. It needs to be fast so both machines get the same view of the game. Any ideas? Thanks
-
Mar 7th, 2009, 06:06 PM
#2
Re: [2008] Sending Variables via network
Sending data through the network is done the same, no matter if its only within the local network or on the internet. The .NET framework contains a System.Net.Sockets namespace with all the classes you need. To gather some basic knowledge on the classes I suggest visiting MSDN and reading about them...TcpClient/TcpListener for TCP communication and UdpClient for UDP communication.
-
Mar 7th, 2009, 08:05 PM
#3
Thread Starter
Hyperactive Member
Re: [2008] Sending Variables via network
ok, hmm but how do i "2008" this :P
Dim serverSocket As New TcpListener(8888)
-
Mar 7th, 2009, 08:05 PM
#4
Re: [2008] Sending Variables via network
The basic decision, in your case, is probably between UDP and TCP. Here are the key points:
TCP is a connection based protocol, while UDP is not. This means that TCP forms a virtual connection between sender and receiver. There is overhead involved with this, but once the connection is established, the message, of any size, will go through completely and in order. UDP is connectionless, so you are sending out packets much like you would mail a letter. The only way to be certain that the letter got through is if the other end replies to it in some way. However, not having a connection makes it easy to set up, and easy to broadcast to multiple listeners, which can be useful in a game.
UDP is faster, but if the size of your message gets larger than the size of the packet being sent, then the message will be fragmented. Since there is no guarantee that any particular package will get through, a fragmented message can be a pain, because any piece may either fail to come through, come through multiple times, or come through out of order. This is rarely an issue with games, since the information needed to keep track of locations in a game is almost always very small. I forget the packet size that is safe, but I think it is in the thousands of bytes.
So to sum it up:
UDP: Fast, simple, needs relatively small packets or else it is more difficult, and packets may be lost, so a reply mechanism is essential for critical packets.
TCP: Slower (though still pretty fast), more difficult to set up, harder to deal with multiple clients, no real limit on the amount of data in any one send, and the message always gets through.
UDP was the basis of many LAN games, such as DOOM, since all that needed to be sent out was tiny bits of information about where items were located. Speed and the ability to broadcast to all listeners were the most important features. If a packet was dropped (it does happen, but it isn't really common in most environments), nothing much was lost, as the characters were moving around so much that a new message would be forthcoming in short order.
I have some UDP classes in a thread over in the networking section that I am using in a robot project. Atheist has some TCP examples in his signature.
My usual boring signature: Nothing
 
-
Mar 7th, 2009, 08:12 PM
#5
Thread Starter
Hyperactive Member
Re: [2008] Sending Variables via network
Oh, i already tore a example project apart, I have a server and client connected sharing numbers, and its a multi client set up, but when i connect a second "dummy" client (all from 1 pc) they all bugger up. Im just going over some errors and trying to convert that 2005 line to 2008. iunno
-
Mar 7th, 2009, 08:46 PM
#6
Re: [2008] Sending Variables via network
There is no specific 2005 nor 2008 version of that line, however that particular constructor overload is obsolete, use this instead:
Code:
Dim serverSocket As New TcpListener(System.Net.IPAddress.Any, 8888)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|