Hey: I have tried and tried to make the following code work to receive UDP transmissions and it will not work. Can anyone spot what the trouble might be? Much appreciated.
Main Code:
Imports System.Net.Sockets
Imports System.Net
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents wsUdp As New Udp()
Private Sub wsUdp_onDataArrival(ByVal Data() As Byte, ByVal
TotalBytes As Integer) Handles wsUdp.onDataArrival
Dim inUDPData As String = wsUdp.BytestoString(Data)
MsgBox("Heres the data " & inUDPData)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Public Class Udp
Public Event onDataArrival(ByVal Data As Byte(), ByVal TotalBytes As Integer)
Public Function StringToBytes(ByVal Data As String) As Byte()
StringToBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
End Function
Public Function BytestoString(ByVal Data As Byte()) As String
BytestoString = System.Text.ASCIIEncoding.ASCII.GetString(Data)
End Function
Sub DataArrival()
Dim bytesread As Integer
Dim wsck As New UdpClient()
Dim done As Boolean = False
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Try
Console.WriteLine("Waiting for broadcast")
Dim socketdata As Byte() = wsck.Receive(RemoteIpEndPoint)
bytesread = socketdata.Length
RaiseEvent onDataArrival(socketdata, bytesread)
Here is a class that I have been working on, you might want to give it a try and see if it works. It can be start like this:
withevents Network As New JWM.Net.UDP
you can invoke this listener like Network.listen(THEPORT)
and has several events.
The file needs to be renamed to a .dll instead of .txt
I don't think you need to register the dll, all i think you need to do is add the refernce. In the solutions explorer right click references and click add reference, then all you do is have to add the dll.
I would post the code but the entire dll is three for four class files that are referenced to each other (one for name resolution, one for listening, etc.)
Also have attatched the file in a zip file just incase it got corrupt or something and added a file that tells you what the events and stuff are.
Jeremy
Last edited by Jeremy Martin; Oct 15th, 2002 at 03:44 AM.