|
-
Mar 10th, 2013, 01:08 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Server Not Responding Issue
I'm getting data from a Server over which I have no control.
Sometimes it does not respond and the code I'm using causes the App to freeze.
Only thing I can think of maybe setting a timer in my program such that if a certain period of time expires
I exit my Sub that called the Server.
UPDATE: Changed to Timer and dropped Sleep (forgot it suspends execution)
Still looking for better alternative.
Code:
'Wait Until Server Returns Records
'or Kill if Error
Do
If (mstrGotRecords = "error") Then
frmHD.Caption = "ERROR - Check and Redo Request"
Exit Sub
Else
If (mstrGotRecords = "fin") Then
Exit Do
Else
Call fWait(3) 'API function
'>>>
End If
End If
Loop
Any other solution appreciated.
Last edited by dw85745; Mar 10th, 2013 at 01:40 PM.
-
Mar 10th, 2013, 05:06 PM
#2
Re: Server Not Responding Issue
What kind of server is it that you're communicating with ?
-
Mar 10th, 2013, 05:15 PM
#3
Thread Starter
PowerPoster
Re: Server Not Responding Issue
Good Question:
I all know is they're running Java and provide an API to access it.
-
Mar 10th, 2013, 06:11 PM
#4
Re: Server Not Responding Issue
Ok...So I assume its a local server ? How is communication to it achieved ? TCP/IP ? Pipes ? Dlls ?
-
Mar 10th, 2013, 09:08 PM
#5
Re: Server Not Responding Issue
With a loop which i do not recommend,
Something like this should work
Code:
Do Until mstrgotrecords = "fin"
DoEvents
If (mstrgotrecords = "error") Then
frmhd.Caption = "ERROR - Check and Redo Request"
Exit Sub
End If
Loop
The way I would do it is with a timer.
Code:
Private Timer_Seconds As Integer
Private Timer_TimeOut As Integer
Private Sub RequestRecord(WaitDelay As Integer, Optional TimeOut As Integer = -1)
Timer_Seconds = 0
Timer_TimeOut = TimeOut
Timer1.Interval = WaitDelay
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Select Case LCase(mstrgotrecords)
Case "error"
frmhd.Caption = "ERROR - Check and Redo Request"
Case "fin"
frmhd.Caption = "FOUND"
Case Else
If TimeOut_Seconds = Timer_Seconds Then
frmhd.Caption "TIMEOUT - Check and Redo Request"
Else
Timer_Seconds = Timer_Seconds + 1
Exit Sub
End If
End Select
Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
RequestRecord 2 'No Timeout, timer will keep going!
'RequestRecord 2, 30 'Timeout after 30 seconds, timer stop after 30 seconds!
End Sub
Edit:
Not sure if once it hits the last "record" and it shows "fin", if so, then forget the timer and use the loop.
Last edited by Max187Boucher; Mar 10th, 2013 at 09:13 PM.
-
Mar 10th, 2013, 10:16 PM
#6
Thread Starter
PowerPoster
Re: Server Not Responding Issue
Thanks both for input:
Niya: Yes it is TCP/IP and remote with another firm.
Max187Boucher:
Yes, you are correct -- the final record is tagged with "fin".
Your first example (loop) basically mirrors mine in that if a final record is received ('fin") or the Server sends some kind of error message I can get out of the loop.
However, if the Server never responds to my request, or hangs then timer only "OUT" I see.
Appreciate you second code -- IMHO, better logic approach
---------------------------------
You might want to look at: 'Source: MSDN Q231298
API Timer and IMHO easier to use than VB's
Last edited by dw85745; Mar 10th, 2013 at 10:28 PM.
-
Mar 15th, 2013, 06:21 AM
#7
Thread Starter
PowerPoster
Re: Server Not Responding Issue
Update:
For those with "Loop Exit" concerns, you might want to check out
API-Guide "Wait Message" example.
Only thing that appears to work in VB's single thread environment without
resorting to a Background Thread or possibly ActiveX
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|