Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

udp socket broadcasting

Posted on 2005-03-25
2
Medium Priority
?
647 Views
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
    bcWinsock.Bind
   
   
End Sub

Private Sub bcWinsock_DataArrival(ByVal bytesTotal As Long)
    Dim helloInfo As String
   
    bcWinsock.GetData helloInfo
    statusText.Text = statusText.Text + helloInfo
   
    'feedback
    bcWinsock.SendData "message received"
   
End Sub
0
Comment
Question by:yuexb
  • 2
2 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 1000 total points
ID: 13637843
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
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 = "255.255.255.255"   ' 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 = "255.255.255.255"
    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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

580 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