Results 1 to 9 of 9

Thread: Winsock arrrggg (PLEASE HELP)

  1. #1

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935

    Angry Winsock arrrggg (PLEASE HELP)

    Okay I have been battling away for some time trying to get a winsock connection working within my app.

    I have written previous apps using the same code and it has worked fine. But now all I get is either "Address in Use Error" or if I change the ports to be 0 to let winsock determine the port I simple get nothing this is driving me insane

    Here is the code im using

    VB Code:
    1. Private Sub Form_Activate()
    2. Dim strIp As String
    3.  
    4. If isLoaded = False Then
    5.     strIp = SckListen(0).LocalIP
    6.     SckListen(0).LocalPort = 1001
    7.     SckListen(0).Listen
    8.     objData.addChatUser User, strIp
    9.    
    10.     If isDemo = True Then
    11.         demoValidate
    12.     End If
    13.    
    14.     isLoaded = True
    15. End If
    16. End Sub
    17.  
    18.  
    19.  
    20. Private Sub SckListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    21. If SckListen(0).State <> sckClosed Then SckListen(0).Close
    22.  
    23. If Index = 0 Then
    24.             intSckIndex = intSckIndex + 1
    25.             Load SckListen(intSckIndex)
    26.             SckListen(intSckIndex).LocalPort = 0
    27.             SckListen(intSckIndex).Accept requestID
    28. End If
    29.  
    30.  
    31. End Sub
    32.  
    33. 'In another form
    34.  
    35. Private Sub cmdChat_Click()
    36. Dim txtSelected
    37. Dim intCount As Integer
    38. Dim isSel As Boolean
    39. Dim strSend As String
    40. Dim strChatName As String
    41. Dim strHost As String
    42. Dim isConnect As Boolean
    43.  
    44. isSel = False
    45.  
    46. For intCount = 0 To List1.ListCount - 1
    47.     If List1.Selected(intCount) = True Then
    48.         isSel = True
    49.     End If
    50. Next intCount
    51.  
    52. If isSel = False Then
    53.     msg = MsgBox("Please Select a user!", vbInformation)
    54.     Exit Sub
    55. End If
    56.  
    57. Set frmChat = New frmClientChat
    58. intFrmChatCount = FrmChatCol.count + 1
    59. strChatName = User & " Session " & intFrmChatCount
    60. frmChat.Tag = strChatName
    61. FrmChatCol.Add frmChat, frmChat.Tag
    62.  
    63.  
    64.  
    65. For intCount = 0 To List1.ListCount - 1
    66.     If List1.Selected(intCount) = True Then
    67.         intSckIndex = intSckIndex + 1
    68.         Load frmDesktop.SckListen(intSckIndex)
    69.         strHost = objData.getChatHost(List1.List(intCount))
    70.         frmDesktop.SckListen(intSckIndex).Connect strHost, 1001
    71.         If frmDesktop.SckListen(intSckIndex).State = sckConnected Then
    72.                 strSend = "REQUEST" & Chr$(182) & User & Chr$(182) & strChatName
    73.                 frmDesktop.SckListen(intSckIndex).SendData strSend
    74.             End If
    75.        
    76.        
    77.     End If
    78. Next intCount
    79.  
    80. frmChat.Show
    81. Unload Me
    82.  
    83. End Sub

    that last sub is little dodgy now as I have been playing around with it trying out different stuff

    Can someone anyone please help me sort this out ??


    Thanks

    PS sorry for reposting this question but I need to resolve it asap as it is holding up my entire project now

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Quick question rudvs2 without really looking to indepth at the code arre you trying to listen and "talk"/send at the same time on the same winsock control? Or soemthing similar.
    I had that problem and i found it but creating 2 different apps one listener and one sender. Then worked backwards.

    Just a suggestion!

  3. #3

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    Hmm I havent tried the two seperate apps yet but I have got it creating a control array so there is only 1 winsock control that is always listening then it adds controls as connection requests come in.

  4. #4
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Try it!

    It is microsoft after all!
    You never know!

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I only took a quick look but isn't this closing your main listening sock.
    VB Code:
    1. If SckListen(0).State <> sckClosed Then SckListen(0).Close

  6. #6

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    yeah it does

    I only threw that in there to try something out

    The error occurs without that line

    PS I still cant get the damn thing working

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Is the 'client' and 'server' both members of the SckListen winsock array? Whats the point of that?

    Don't you want your array to be the 'server' and a single sock for the 'client'? The frmDesktop.SckListen(intSckIndex).Connect strHost, 1001 confuses me.

    Are you making a chat app? I just redid you I made awhile ago. Let me know if you want to trade notes, code, whatever.

  8. #8
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Info.

    The LocalPort property is being set to 0 for new instances of the winsock control.

    For servers, this defines the port for which a connection listens on. If the client assumes the remote port is 1001 (which it connects on in your example), then the client will try and send data to port 1001... yet the local port of the server is set to 0 (or random) when a connection request occurs... This might explain why you're not recieving data.

    Try not setting the local port property of new instances in the connection request event to 0. i.e.
    VB Code:
    1. Private Sub SckListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.  
    3.     If Index = 0 Then
    4.    
    5.             intSckIndex = intSckIndex + 1
    6.             Load SckListen(intSckIndex)
    7.            
    8.             'Check to see if we're closed.
    9.             If SckListen(intSckIndex).State <> sckClosed Then
    10.                 SckListen(intSckIndex).Close
    11.                 DoEvents
    12.             End If
    13.  
    14.             'Accept.
    15.             SckListen(intSckIndex).Accept requestID
    16.     End If
    17.  
    18.  
    19. End Sub

    This will accept connections on port 1001. The local port properties for new controls loaded at runtime will also be 1001.

    It might be an idea to try coding seperate server/client projects. It will make things easier to deal with.

    Hope this helps.
    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  9. #9

    Thread Starter
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    Edneeis

    The reason I am trying to do it all from an array is and I do not want to create seperate server client apps is because this is an extra feature in another app i am writing. The users will be able to see who is logged on via a central database that is updated when they run this application.

    I want multiple chat sessions to be able to take place IE the user can recieve a chat request and start a conversation. Then the user can opt to also create another chat with another users or invite others into your exsisting chat. Much like all the chat apps work.

    I thought in theory what I am trying to do should work. But I guess im wrong there

    PS I would be glad to trade notes as I really have to resolve this and get something happening very very quickly now.

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