-
Udp Receiver
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
End Sub
End Class
'UDP STUFF
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
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)
Console.WriteLine("Received broadcast from {0} :" + _
ControlChars.Cr + " {1}" + ControlChars.Cr, _
RemoteIpEndPoint.ToString, _
Encoding.ASCII.GetString(socketdata, 0, socketdata.Length))
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub
End Class
:confused:
-
1 Attachment(s)
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
Jeremy
-
dll wont register
Hi thanks for your Dll!
I renamed the file to a dll then tried to regsiter it on windows and got the following error:
c:\vbnet\networkutilities.dll was loaded, bu the DllRegisterServer entry point was not found.
DllRegisterServer may not be exported, or a corrupt version of c:\vbnet\networkutilities.dll may be in memory.
Consider using PView to detect and remove it.
Any ideas? Im using windows 2k.
thanks
-
-
1 Attachment(s)
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