4
Answers

updatepanel with timer problem

chandra kumar

chandra kumar

11y
972
1
Hi friends i am new to socket programming in asp .net c#. Currently i want to receive real time data from socket and display the data in web page using updatepanel. For this i have used a timer with update pannel. Because of using timer i think the page_load event is fired continiously and multiple instances of socket are created and it gives error" Only one instance of socket/port no permitted......".

HOW shoul i arrange the code so that socket creation  will take only once.please suggest.




<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
<br />
            <asp:Timer ID="Timer1" runat="server" Interval="1000">
            </asp:Timer>
            <br />
            <br />
            <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="50pt"
             Text="Label"></asp:Label>
            <br />
            <br />
            <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="50pt"
                Text="Label"></asp:Label>
            <br />
          
            <br />
           
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>




code behind is like this


  protected void Page_Load(object sender, EventArgs e)
    {
      Label1.Text = System.DateTime.Now.ToLongTimeString();
         

    // socket creation part

      IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 4321);
      s.Bind(ipep);
      IPAddress ip = IPAddress.Parse("226.1.1.1");
      s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
      new MulticastOption(ip, IPAddress.Any));

     


    // data receive and display
      DataSize = s.Receive(databuffer);
      raw = System.Text.Encoding.ASCII.GetString(databuffer);
      Label2.Text = raw;

    }
Answers (4)