Results 1 to 5 of 5

Thread: Udp Receiver

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Posts
    26

    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



  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    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
    Attached Files Attached Files

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Posts
    26

    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

  4. #4
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    USA
    Posts
    432
    Just post the code !

  5. #5
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    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
    Attached Files Attached Files
    Last edited by Jeremy Martin; Oct 15th, 2002 at 03:44 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width