Results 1 to 6 of 6

Thread: [2008] Sending Variables via network

  1. #1

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    [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

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Re: [2008] Sending Variables via network

    ok, hmm but how do i "2008" this :P


    Dim serverSocket As New TcpListener(8888)

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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

  5. #5

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    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

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width