Results 1 to 2 of 2

Thread: Problem with winsock server and client communication....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    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:
    1. [B]This code is on Form1[/B]
    2. Private Sub Listener_ConnectionRequest(ByVal requestID As Long)
    3. Dim i As Byte
    4.     With Listener
    5.         For i = 1 To xClient.UBound
    6.             If xClient(i).Sock_State = sckClosed Then
    7.                 xClient(i).Accept requestID
    8.                 Exit For
    9.             End If
    10.         Next
    11.     End With
    12.  
    13.     If xClient(xClient.UBound).Sock_State <> 0 Then
    14.         DoEvents
    15.         Load xClient(xClient.UBound + 1)
    16.     End If
    17. End Sub
    18.  
    19. [b]Code on xSocks User Controls[/b]
    20.  
    21. Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
    22. On Error Resume Next
    23. Dim x As String
    24. Dim iClient As Integer
    25. Dim i As Byte
    26. Dim iTmp As Byte
    27.  
    28.     'Data Arrival inform of x
    29.     xSocks.GetData x
    30.  
    31.     Select Case Left(x, 2)
    32.         Case "ID"
    33.             iClient = Split(x, "~")(1)
    34.  
    35.             'check if ID# is in Server allow range
    36.             If iClient >  TotalComps Then
    37.                 SendData "ER" & "~" & "Error3" & "~" & TotalComps
    38.             End If
    39.            
    40. [COLOR=DarkOrange]'Check if ID# is used
    41.             For i = 1 To form1.xClient.UBound - 1
    42.                 If form1.xClient(i).xNum = iClient Then
    43.                     Unload form1.xClient(i)
    44.                     xNum = 0
    45.                    Exit For
    46.                 End If
    47.             Next
    48. [/COLOR]
    49.            
    50.             'Check for maximum connection
    51.             If iTmp > TotalComps Then
    52.                 SendData "ER" & "~" & "Error2"
    53.                 Exit Sub
    54.             End If
    55.            
    56.             xNum = iClient
    57.            
    58. 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...

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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
  •  



Click Here to Expand Forum to Full Width