|
-
Apr 22nd, 2008, 05:48 PM
#1
Thread Starter
Lively Member
[VB6] Multiple UDP Connections
I'm using this UDP Server & Client Code. Any way to make it accept multiple connections at once?
CLIENT:
Code:
Option Explicit
Private Sub cmdGO_Click()
txtHost.Text = Trim$(txtHost.Text)
txtPort.Text = Trim$(txtPort.Text)
If Len(txtHost.Text) > 0 And Len(txtPort.Text) > 0 And _
IsNumeric(txtPort.Text) And Len(txtData.Text) > 0 Then
sckClient.RemoteHost = txtHost.Text
sckClient.RemotePort = CInt(txtPort.Text)
sckClient.Bind 1024
sckClient.SendData txtData.Text
End If
End Sub
SERVER:
Code:
Option Explicit
Private Sub Form_Load()
sckServer.Protocol = sckUDPProtocol
sckServer.LocalPort = 3794
sckServer.Bind 3794
Me.Caption = "Server - OPEN"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
sckServer.Close
End Sub
Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
sckServer.GetData strData, vbString, bytesTotal
Debug.Print strData
Me.Caption = "DATA RECEIVED"
End Sub
-
Apr 22nd, 2008, 06:17 PM
#2
Re: [VB6] Multiple UDP Connections
There is no such thing as multiple connections when you deal with UDP, since UDP is connection-less.
Just send data to the same port, and make sure you identify each packet properly
-
Apr 22nd, 2008, 06:32 PM
#3
Thread Starter
Lively Member
Re: [VB6] Multiple UDP Connections
I don't get how to do it.
EDIT: Do I do like this?
Code:
sckServer.RemotePort = 7777
sckServer.RemoteHost = "127.0.0.1"
sckServer.SendData "SOMETHING HERE"
'Then to send to other client
sckServer.RemotePort = 7777
sckServer.RemoteHost = "127.1.2.3"
sckServer.SendData "HJDSH"
Last edited by Hellomy; Apr 22nd, 2008 at 06:39 PM.
-
Apr 22nd, 2008, 06:54 PM
#4
Re: [VB6] Multiple UDP Connections
I haven't dealt with VB6 UDP in about 10 years, but yes, it should be as simple as that. With UDP, you are just firing the data off into the ether in the hopes that it will arrive at the correct destination. It is much like sending a letter in that you put the right address on it and send it off. If the address is right, and the system is working, the message should get through. On the other hand, if the sytem goes down, or something else happens to disrupt your packet, you'll never know. The advantage to UDP is simplicity and speed, but the cost is uncertainty about receipt.
My usual boring signature: Nothing
 
-
May 4th, 2008, 07:40 AM
#5
Member
Re: [VB6] Multiple UDP Connections
With that being said would a person need to incorporate a timer in order to make sure that two packets dont get sent out simultaniously? I set up a timer that waits a half second before it sends another packet is that necessary or not really?
-- Josh Smith
C#, VB, PHP, SQL
-
May 4th, 2008, 12:21 PM
#6
Fanatic Member
Re: [VB6] Multiple UDP Connections
This sounds like you should be using TCP and not UDP. UDP is only used if you don't care if the packet is out of order ect. But, TCP makes sure the packet comes in the right order.
-
May 4th, 2008, 04:52 PM
#7
Member
Re: [VB6] Multiple UDP Connections
-- Josh Smith
C#, VB, PHP, SQL
-
May 5th, 2008, 06:39 PM
#8
Re: [VB6] Multiple UDP Connections
A half second delay is a lifetime in UDP. I'm not as sold on TCP based on the original example. UDP is ideal for sending small packets very fast. If the amount of information is larger than the packet size, then you really could have issues, and UDP wouldn't be such a good choice. However, with TCP, packet size isn't an issue, but you have to deal with connections, and it's slower.
There are advantages and disadvantages to both.
My usual boring signature: Nothing
 
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
|