|
-
Apr 10th, 2005, 01:02 PM
#1
Thread Starter
Addicted Member
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
-
Apr 10th, 2005, 01:32 PM
#2
Junior Member
Re: Multithread Multiuser UDP Winsock Client/Server
 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,
-
Apr 10th, 2005, 02:10 PM
#3
Re: Multithread Multiuser UDP Winsock Client/Server
Jacob123,
Remember UDP packets are not guarenteed to be delivered, TCP packets are.
-
Apr 10th, 2005, 02:12 PM
#4
Thread Starter
Addicted Member
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.
-
Apr 10th, 2005, 06:01 PM
#5
Re: Multithread Multiuser UDP Winsock Client/Server
Here is an example of sending data via UDP
VB Code:
With Winsock
.Protocol = sckUDPProtocol
.RemoteHost = m_Server
.RemotePort = 123
.Bind
.SendData MyData
End With
-
Apr 14th, 2005, 04:37 PM
#6
Thread Starter
Addicted Member
Re: Multithread Multiuser UDP Winsock Client/Server
I understand single client/server UDP, but multi user is the one thats giving me problems!
-
Apr 14th, 2005, 08:32 PM
#7
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.
-
Apr 15th, 2005, 05:57 PM
#8
Re: Multithread Multiuser UDP Winsock Client/Server
OK, see if this helps out
Server
VB Code:
Private Sub Form_Load()
Winsock1.Close
Winsock1.Protocol = sckUDPProtocol
Winsock1.Bind IPPort
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim str As String
Winsock1.GetData str, vbString
Debug.Print "**"; str
Debug.Print "Remote Host = "; Winsock1.RemoteHost
Debug.Print "Remote IP = "; Winsock1.RemoteHostIP
Debug.Print "Remote Port = "; Winsock1.RemotePort
Winsock1.SendData "Hello Back"
End Sub
Client
VB Code:
Private Sub Command1_Click()
Winsock1.Close
Winsock1.Protocol = sckUDPProtocol
Winsock1.RemoteHost = IPAddress
Winsock1.RemotePort = IPPort
Winsock1.SendData "Hello"
End Sub
-
Apr 16th, 2005, 01:14 AM
#9
Thread Starter
Addicted Member
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
-
Apr 16th, 2005, 01:22 AM
#10
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?
-
Apr 16th, 2005, 04:47 AM
#11
Thread Starter
Addicted Member
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!
-
Apr 16th, 2005, 12:51 PM
#12
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.
-
Apr 16th, 2005, 06:20 PM
#13
Thread Starter
Addicted Member
Re: Multithread Multiuser UDP Winsock Client/Server
 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?
-
Apr 16th, 2005, 07:04 PM
#14
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
-
Apr 16th, 2005, 07:28 PM
#15
Thread Starter
Addicted Member
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.
-
Apr 16th, 2005, 11:41 PM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|