2013-03-27 4 views
0

채팅 응용 프로그램을 개발하려고합니다. 서버 측에 asynchronous calls을 얻기 위해 AjaxPro Framework을 사용하는 Asp.Net2.0 및 vs2005.Iam을 사용하고 있습니다.AjaxPro Framework의 타임 아웃 기능이 작동합니까?

내 문제는 몇 초 후에 timeout 오류가 발생하는 메시지를 보내는 경우입니다. 문제는 무엇이며 어떻게 해결할 수 있습니까?

내 다른 의심의 여지가 그 Heres는 내가 클라이언트 측에서 사용한 코드는 메시지

<script language="javascript"> 
      // Send messages 
     function sendMessage() 
     {    
      // input box for entering message 
      var ta_content = el("txtcontent"); 

      // if the content input is not empty 
      if (ta_content.value.length > 0) 
      { 
       //the message show area 
       var div_recentMsg = el("recentMsg");   

       var clientUname=document.getElementById("<%=hFieldClientUserName.ClientID %>").value;  

       var adminUname=document.getElementById("<%=hFieldAdminUserName.ClientID %>").value; 

       // send the message 
       AjaxProChat.SendMessage(clientUname,adminUname,ta_content.value); 

       // clear the input box 
       ta_content.value = ""; 

       // roll up the web page with the messages 
       ta_content.scrollIntoView(false); 

       getNewMessage(); 


      } 
     } 


     //Obtain the new messages 
     function getNewMessage() 
     { 
      // AjaxProChat.timeouPeriod(1800000); 
      // the user name 
      var username = document.getElementById("<%=hFieldClientUserName.ClientID %>").value;   

      // the message show area 
      var div_recentMsg = el("recentMsg"); 

      // Obtain the DataTable for the newest messages 
      var dt = AjaxProChat.GetNewMsg(username).value; 
      for (var i = 0;i < dt.Rows.length;i++) 
      { 

       // one message in response to one <span> object 
       var oneMsg = document.createElement("span"); 

       // the message sender and corresponding sent content 
       var strLine1 = dt.Rows[i].Sender + " says: (" + dt.Rows[i].SendTime + ")"; 
       strLine1 = DealBrackets(strLine1); 

       // the content of the message 
       var strLine2 = dt.Rows[i].Contents; 
       strLine2 = DealBrackets(strLine2); 

       // show style 
       oneMsg.innerHTML = "<pre>" + strLine1 + "<br>&nbsp;&nbsp;" + strLine2 + "</pre>"; 
       oneMsg.style.padding = "2px 2px 2px 2px"; 
       oneMsg.style.color = (dt.Rows[i].Sender == username) ? "blue" : "red"; 
       oneMsg.style.fontFamily = "'Courier New'"; 

       // attached to DOM 
       div_recentMsg.appendChild(oneMsg); 
      } 
     } 


</script> 

Heres는 HTML 코드를 보내 AjaxPro Framework

사용에 심각한 문제가된다

<div style="text-align: center"> 
    <strong><span style="font-size: 24pt"><span style="color: #333399; background-color: #ffffff"> 
     Chatting Room</span></span></strong> 

</div> 
    <table border="2" style="width: 792px; height: 443px;background-color:#ffffff;"> 
     <tr> 
      <td colspan="3" style="height: 373px; width: 729px;"> 
       <div id="recentMsg" style="width: 779px; height: 368px; overflow:auto;"> 
       </div> 
      </td> 
     </tr> 
     <tr> 
      <td colspan="3" style="height: 30px; width: 729px;"> 
       <asp:Label ID="Label1" runat="server" Font-Size="X-Large" ForeColor="Maroon">Input the message and click Send or press ENTER key:</asp:Label> 
      </td> 
     </tr> 
     <tr> 
      <td colspan="3" style="height: 40px; width: 729px;"> 
       <input id="txtcontent" onkeydown="if (event.keyCode==13) {sendMessage();return false;}" 
        style="width: 55%; height: 30px" type="text" runat="server" />   
       <input onclick="javascript:sendMessage();" style="width: 58px; border-top-style: groove; 
        border-right-style: groove; border-left-style: groove; background-color: #ebf1fa; 
        border-bottom-style: groove; height: 34px;" type="button" value="Send" id="btnSend" /></td> 
     </tr> 
     <tr> 
      <td colspan="3" style="width: 729px"> 
      </td> 
     </tr> 
    </table> 

내가 서버 쪽에서 작성한 메시지를 보내고 받기위한 코드를 작성합니다.

[AjaxPro.AjaxMethod]//code for sending messages 
public void SendMessage(string Sender,string Receiver,string Content) 
{ 
    ChatBAL clsChat = new ChatBAL(); 
    clsChat.SENDER = Sender; 
    clsChat.RECEIVER = Receiver; 
    clsChat.CONTENT = Content; 
    clsChat.SendMessage(); 

} 

[AjaxPro.AjaxMethod]//code for getting latest message and returns datatable 
public DataTable GetNewMsg(string UserName) 
{ 
    ChatBAL clsChat = new ChatBAL(); 
    DataTable dtNewMsg =new DataTable(); 
    try 
    { 
     clsChat.USERNAME = UserName; 
     dtNewMsg = clsChat.GetNewMessage();    
    } 
    catch 
    { 
     throw; 
    } 
    finally 
    { 
     clsChat = null; 
    } 
    return dtNewMsg; 
} 

답변

0

자바 스크립트 코드에서이 코드는 ajax 호출 바로 전에 사용할 수 있습니다.

AjaxPro.timeoutPeriod = 120 * 1000; //this will add a 2 minutes timeout 
    AjaxPro.onTimeout = (function (time, obj, something) { 
     if (time < AjaxPro.timeOutPeriod || obj.method !="SendMessage") return false; 
     else 
     { 
      console.log("Ajaxpro timeout exception after 120 seconds!"); 
     } 
    });