|
-
Feb 15th, 2007, 09:45 AM
#1
Thread Starter
Addicted Member
Problem with winsock server and client communication....
Hello guys!!! I have this problem with winsock communication... I have form1 and user controls I call it xSocks, below is my code. on form1 i have wsk listener.
xClient is xSocks User control that I used and I create a new socket on form1 for Listener purpose.
VB Code:
[B]This code is on Form1[/B]
Private Sub Listener_ConnectionRequest(ByVal requestID As Long)
Dim i As Byte
With Listener
For i = 1 To xClient.UBound
If xClient(i).Sock_State = sckClosed Then
xClient(i).Accept requestID
Exit For
End If
Next
End With
If xClient(xClient.UBound).Sock_State <> 0 Then
DoEvents
Load xClient(xClient.UBound + 1)
End If
End Sub
[b]Code on xSocks User Controls[/b]
Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
Dim x As String
Dim iClient As Integer
Dim i As Byte
Dim iTmp As Byte
'Data Arrival inform of x
xSocks.GetData x
Select Case Left(x, 2)
Case "ID"
iClient = Split(x, "~")(1)
'check if ID# is in Server allow range
If iClient > TotalComps Then
SendData "ER" & "~" & "Error3" & "~" & TotalComps
End If
[COLOR=DarkOrange]'Check if ID# is used
For i = 1 To form1.xClient.UBound - 1
If form1.xClient(i).xNum = iClient Then
Unload form1.xClient(i)
xNum = 0
Exit For
End If
Next
[/COLOR]
'Check for maximum connection
If iTmp > TotalComps Then
SendData "ER" & "~" & "Error2"
Exit Sub
End If
xNum = iClient
and so on...............
My problem is the orange part... my project is working well except if workstation is terminated abnormally e.i power Off, power shutdown, Uplug pc... so in this point the connection of the client and server is disconnected abnormal, On server side the bound index is still loaded, so when I try to reconnect the workstation get connected however it won't allow to used the previous bound index which the client workstation need in order to make a connection to the server. so what I would like to do is that if the workstation try to reconnect to the server the server will unload the bound index previouslly used by workstation, and re assign it again...
anyone pls. need help badly... tnx in advance...
-
Feb 15th, 2007, 01:02 PM
#2
Re: Problem with winsock server and client communication....
Ping the client every so often. If one or more pings fail, disconnect the client. How often, and how many pings, is up to you.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
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
|