Can a web service receive UDP packets ? RRS feed

  • Question

  • User713711876 posted

    I have a hosted web application / web service that needs to receive UDP packets. Thinking that this was not possible, I went ahead and wrote a UDP server in Windows Forms based on some code I found on another forum. I recently revisited the forum and found that another developer had decided to put the code to initialize the UDPClient into the init() of the global.asax of a web application and apparantly it worked......

    <code>Public Overrides Sub Init()

    SocketNO = 80
    receivingUdpClient = New System.Net.Sockets.UdpClient(SocketNO)
    ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages)

    End Sub</code>

    The ReceiveMessages method contains a DO statement at the top and LOOP WHILE TRUE at the end of the routine. It then contains code to handle the UDP Packet.

    I am considering placing this code in the global.asax of one of my web services.

    Does anyone have any comments about possible pitfalls of this or suggestions as to other ways to get UDP packets to a web application ?

    Friday, April 21, 2006 6:15 PM

All replies

  • User-1525784084 posted
    Yeah, you can do it, just place the code in global.asax. I've did the smae, but it was TCP Packets.
    Saturday, April 22, 2006 9:34 AM
  • User713711876 posted

    I've experimented for hours but cannot get anything to work. I need an overview of how this should work....


    1. What ports should the remote client send the packet on and can I receive on a different port ?

    I have to send on port 80 so the packet can arrive at the web service, but cannot create a UDPClient on port 80 as an exception is thrown that the port is already in use.

    2. The Init() method in Global.asax - should it create a new thread each time a packet arrives, or should it create a continous loop the first time it runs ?

    Any suggestions apprciated.

    Sunday, April 23, 2006 2:47 AM
  • User-1525784084 posted
    You can receive packets on any ports you want.
    Monday, April 24, 2006 6:00 AM
  • User1227458817 posted

     hi steve did you make it worked?

    i just did same thing and put the code in the init()

    but i have to open the web page to start the aplication after that i get one packet but could not get the rest of it


    Wednesday, July 29, 2009 2:47 AM
  • User1071970124 posted

    Did you notice that you're replying to a post from more than three years ago?

    Please start a new thread. They cost the same amount as replying to an old thread, but people will laugh at you less.

    Wednesday, July 29, 2009 9:39 AM
  • User-1637530625 posted

    something wrong with replying to a post from more than three years ago?  

    Hope you learned manners since then.

    Tuesday, April 16, 2013 1:29 AM