Results 1 to 2 of 2

Thread: Displaying UDP messages on a page.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2013
    Posts
    1

    Displaying UDP messages on a page.

    Hello. New user here. I am using ASP.Net 4.0, VB.Net, IIS7, and VWD2010 Express. I am somewhere between an Advanced Beginner and Intermediate user (just so you know my knowledge level).

    I have a requirement to show UDP messages in a page as they happen on the network. We have devices on our network sending out messages to a specific port (Port 11000 in my example). The page I am trying to create will be loaded by different users to simply see the activity and status of these devices. This is a project I am doing in my free time to try and learn a little more...

    I think I found the end of the Internet trying to find examples of this being done, but I can not find anywhere where anybody is actually showing these messages on a page as they become available. There are of course tons of udp server/client examples in VB.Net, C, and so on but they are all console apps, Wondows Forms, and so on. So, I am here looking for suggestions.

    My thought was to try and create a Web Service (first one for me) that can get the messages and the page would access the web service and simply return the current message.

    What I have so far (in debug mode) works except I have a couple problems. (I know this is kinda lame, but again it is somewhat of a side project for me to learn from as well as a bit of a proof of concept type thing.)

    • The port doesn't seem to always get released (on the IIS Server-I see this in TcpView) so when I stop the page (from a Stob button that disables the timer) and restart, I sometimes get an error indicating only one use of the port is allowed.
    • If I run the page outside of VWD2010 (i.e, from the IIS server) it simply doesn't work. The page hangs and times out. In an error log I find the message indicating Only one usage of each socket address.
    • When I am running this in Debug and I open IE on another PC and try to run the page, everything locks up i.e. the page and IIS - I have to do an IISRESET to release the port.


    I believe I have port releasing issues and maybe security issues as well, but can't figure it out. I'm beyond my knowledge level trying to figure it out, but trying....

    My code so far: The .aspx has a Start button which enables a timer control. Each tick of the timer fires:
    Code:
    Dim s As String = Service.DoWork()
    TextBox1.Text = TextBox1.Text + vbCrLf + s
    Service.DoWork returns the message and is displayed in a textbox.
    My Service.DoWork is:
    Code:
    Public Shared Function DoWork() As String
      Dim udpClient As New UdpClient(11000)
      Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
      Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
      Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
          returnData = returnData + " from " + RemoteIpEndPoint.Address.ToString() + " their port number " + RemoteIpEndPoint.Port.ToString()
      System.Diagnostics.Debug.WriteLine(returnData)
    
      udpClient.Client.Close()
      udpClient.Client.Dispose()
      udpClient = Nothing
    
      Return returnData
    End Function
    Maybe showing UDP messages in a web page using asp.net and vb.net isn't even possible(?). Any suggestions on how to correct what I am doing wrong would be appreciated.

    I know I can use jquery, ajax, update panels, timers, SignalR, and so on to display the messages, I just can't get the messages reliably.

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: Displaying UDP messages on a page.

    If your calling the function on each timer tick your error suggests that your port connection isn't released before you try and make another. You could check the state of the udpClient object before trying to make a new one once that works I'd call it every couple of seconds not every tick.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

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