udp socket broadcasting

Posted on 2005-03-25
Medium Priority
Last Modified: 2013-11-13
hi, all,

im trying to write a small application that listens to a device and respond thru udp socket. neither the device nor the program knows the ip address of each other. but i think udp socket can do broadcasting. my program receives the packet, but the responding packet it sends out can't be received (or maybe the packet can't be sent out). does anyone have any idea on this problem? here's my code:

Private Sub Form_Load()
    bcWinsock.Protocol = sckUDPProtocol
    bcWinsock.RemotePort = 1111
    bcWinsock.LocalPort = 1007
End Sub

Private Sub bcWinsock_DataArrival(ByVal bytesTotal As Long)
    Dim helloInfo As String
    bcWinsock.GetData helloInfo
    statusText.Text = statusText.Text + helloInfo
    bcWinsock.SendData "message received"
End Sub
Question by:yuexb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 29

Accepted Solution

nffvrxqgrcfqvvc earned 1000 total points
ID: 13637843
LVL 29

Expert Comment

ID: 13639238
'UDP Broadcasting

'Admin Side
Add 1 Winsock Control named Winsock1
Set Winsock control to UDP protocal
Add 1 Command Button named Command1
Add the following code to the Form

Private Sub Command1_Click()
Dim sTr As String
sTr = "Broadcast using UDP"
Winsock1.SendData sTr
End Sub

Private Sub Form_Load()
With Winsock1
        .RemoteHost = ""   ' Broadcast IP
        .RemotePort = 2001         ' Port to connect to.
        .Bind 2002                       ' Bind to the local port.
    End With

End Sub

'Server Side
Add 1 Winsock Control named Winsock1
Set Winsock control to UDP protocal
Add the following code to the Form

Private Sub Form_Load()

    Winsock1.RemotePort = 2002
    Winsock1.RemoteHost = ""
    Winsock1.Bind 2001

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sTr As String
Winsock1.GetData sTr
MsgBox sTr, vbInformation, "UDP Broadcasting"

End Sub

'Thats it that will broadcast using UDP without knowing the IP address.
'Please remember than when using UDP it is only for LAN, UDP packets will not reach pass the router.

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question