Results 1 to 16 of 16

Thread: Multithread Multiuser UDP Winsock Client/Server

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Multithread Multiuser UDP Winsock Client/Server

    Can someone please direct me to an example like this. I have to use UDP because tcp is slow at sending packets. And I'm not too sure on how to use udp.

    I know it needs no connection but I've just been having problems sending data to the right computers.. I can't explain. can someone show me an example of like a chat that uses multiuser udp. Like I only need to send data to one person for things like private messaging and it seems udp is sending the data to all persons..

    please help
    thanks

  2. #2
    Junior Member
    Join Date
    Nov 2003
    Posts
    22

    Re: Multithread Multiuser UDP Winsock Client/Server

    Quote Originally Posted by Jacob123
    Can someone please direct me to an example like this. I have to use UDP because tcp is slow at sending packets. And I'm not too sure on how to use udp.
    TCP is plenty fast for a chat application. IRC and most of the popular IM protocols are TCP-based.

    Regards,

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Multithread Multiuser UDP Winsock Client/Server

    Jacob123,

    Remember UDP packets are not guarenteed to be delivered, TCP packets are.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    I understand the differences. Its not a chat application. Its a project that requires maximum delivery SPEED of packets.
    Last edited by Jacob123; Apr 10th, 2005 at 02:22 PM.

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    Here is an example of sending data via UDP
    VB Code:
    1. With Winsock
    2.  .Protocol = sckUDPProtocol
    3.  .RemoteHost = m_Server
    4.  .RemotePort = 123
    5.  .Bind
    6.  .SendData MyData
    7. End With

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    I understand single client/server UDP, but multi user is the one thats giving me problems!

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    The code I posted was for the client side. I have used it sucessfully to communicate with UDP servers such as NTP servers. I have never created a UDP server.

    On the server end, what have you tried that did not work?
    Notice that on the client side the bind method is used without specifying a port number. Meaning, I assume, that the client side local port is set by the server.

    I assume that when the server gets a request on it's local port, it chooses a new remote port to communicate on as is done with TCP.

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    OK, see if this helps out
    Server
    VB Code:
    1. Private Sub Form_Load()
    2.    Winsock1.Close
    3.    Winsock1.Protocol = sckUDPProtocol
    4.    Winsock1.Bind IPPort
    5. End Sub
    6.  
    7. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    8.    Dim str As String
    9.    Winsock1.GetData str, vbString
    10.    Debug.Print "**"; str
    11.    Debug.Print "Remote Host = "; Winsock1.RemoteHost
    12.    Debug.Print "Remote IP = "; Winsock1.RemoteHostIP
    13.    Debug.Print "Remote Port = "; Winsock1.RemotePort
    14.    Winsock1.SendData "Hello Back"
    15. End Sub
    Client
    VB Code:
    1. Private Sub Command1_Click()
    2.     Winsock1.Close
    3.     Winsock1.Protocol = sckUDPProtocol
    4.     Winsock1.RemoteHost = IPAddress
    5.     Winsock1.RemotePort = IPPort
    6.     Winsock1.SendData "Hello"
    7. End Sub

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    That still doesn`t explain how i can get the server to send data to individual peers and stuff

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    The client requests data from the server (Hello),
    the server sends the requested data back to the clent (Hello Back)

    Are you trying to do something different than that?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    I have 2 people..

    They always send their ingame coordinates to the server..

    The server gets player1's coordinates and sends them to player 2
    The server gets player2's coordinates and sends them to player 1

    Thats basically what im trying to accomplish!

  12. #12
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    Each client has to send an initialization to the server
    The server stores their IP addresses
    When a coordiante arrives from client1, set RemoteIP to client2 and send data.

    Alternatively you could just broadcast all data to everyone.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    Quote Originally Posted by moeur
    Each client has to send an initialization to the server
    The server stores their IP addresses
    When a coordiante arrives from client1, set RemoteIP to client2 and send data.

    Alternatively you could just broadcast all data to everyone.
    How will the server know that a "coordinate arrives from client1" ??? How will it know its not from client2?

  14. #14
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    How will the server know that a "coordinate arrives from client1" ??? How will it know its not from client2?
    You could handle this in a couple ways.

    The server can check the RemoteHostIP when a message arrives to see who is sending the message.

    Or, as part of the message sent to the server the client could include a predetermined ID number.

    Another thing you could do is:
    Client sends initialization message to server
    server responds with unique port number, loads new winsock control bound to that port number
    client uses this new port number for sending it's coordinates

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Location
    Cleveland, Ohio
    Posts
    255

    Re: Multithread Multiuser UDP Winsock Client/Server

    moeur you seem to know a lot about what im trying to do

    Do you have a msn or aim application that I can contact you with? All i need is an extremely basic (working) example that does what your saying.

  16. #16
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Multithread Multiuser UDP Winsock Client/Server

    From your initial post I assumed you had something working with TCP. Can you post what you have and we can adjust it?

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