Click here to Skip to main content
15,885,020 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, All,

I have an existing UDP Server Application that accepts incoming UDP packets and sends out UDP packets. The application is written in C++.

I am now developting a new web site that wants to talk to the existing Server Application. So I am using UDPClient to send and receive packets from and to the Server Application. This all works fine in the Visual Studio(2008) environment using the ASP.NET Development Server. However, when I deploy the web site to the IIS7 Web Server, no UDP packet were sent nor receiver. No error messages reported either. I wonder if anyone experienced similar problems before and aware of any solutions ?

Some sample code are as follows;


File AspxService.aspx.cs
using System;
using System.Web;
using AspxServer;
public partial class AspxService : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AspxServer.HeartBeatToMainServer();
        //....
    }
}



File AspxServer.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace AspxServer
{
   public class ASocket
   {
      private static ASocket _theSocket = new ASocket();

      public static HeartBeatToMainServer()
      {
         _theSocket.SendBeartBeat();
      }
      private void SendHeartBeat()
      {
         byte[] sendBuf = BitConverter.GetBytes((UInt16) 1000);
        _sockObj.Send(sendBuf, 2);
      }

      private UdpClient _sockObj = null;
      public ASocket()
      {
         try
         {// Create the socket and set remote server on localhost port 1001
            _sockObj = new UdpClient("localhost", 1001);
            _sockObj.BeginReceive(ReceiveCallback, null);
         }
         catch (Exception ex){ }
      }
	
      private void ReceiveCallback(IAsyncResult res)
      {
         IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
         byte[] dataBytes = _aSocket.EndReceive(res, ref remoteEP);
         //....
	_sockObj.BeginReceive(ReceiveCallback, null);
      }
   }
}
Posted
Comments
Ciumac Sergiu 5-Apr-11 10:24am    
It's difficult to state what is the cause of the problem. Don't know whether it helps but I would take a look on the firewall setting for port 1001.
Member 3151821 5-Apr-11 12:17pm    
Thanks for commenting. This had been tried before posting with firewalls turned OFF altogether, but no effect. Thanks!
Nathan St 9-Apr-11 7:29am    
Have you tried running a network listener tool to see if anything is being sent? Have you checked your IAsyncResult for network/port exceptions? (I seem to remember reading somewhere that singletons in .NET apps are just singletons for the current application domain, therefore you could have a port collision going on?) Just my few random thoughts - hope it helps :)
Member 3151821 11-Apr-11 7:43am    
Thanks for the comment. I had IP Sniffer turned on which did not report and activity on the port. "singletons in .NET...", I thinks this should not be a problem since the program works with ASP.NET Development Web Server.
Thanks again for your comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900