Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please
Winsock nub, need help please Winsock nub, need help please
Winsock nub, need help please
Go Back  Xtreme Visual Basic Talk > > > Winsock nub, need help please


Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2005, 09:26 PM
1cemage 1cemage is offline
Newcomer
 
Join Date: Feb 2005
Posts: 6
Default Winsock nub, need help please


i was working on a server, client application to rout updates amont 30 available user sockets... half the time it tells me that i am using the wrong protocal when i conenct the client to the server and the other half the time it conencts just fine... then when i close the client and repoen it to reconenct to the server it errors out saying that i am using the wrong protocal. also, i cant connect multiple clients to one server (even though i have it set up to work with multiple incomming connections through an array of winsock controls)

please help me. source below. sorry for the unlabled opbjects.



SERVER


Code:
Const maxcon As Integer = 30
Dim sockets(maxcon) As Boolean

Private Function GetFreeSocket() As Integer
    Dim i As Integer
    For i = 1 To maxcon
        If sockets(i) = False Then
            GetFreeSocket = i
            Exit Function
        End If
    Next i
    GetFreeSocket = 0
End Function

Private Function InitAcceptSockets() As Boolean
    On Error GoTo err
    Dim i As Integer
    For i = 1 To maxcon
        Load WS(i)
    Next i
    InitAcceptSockets = True
    Exit Function
    
err:
    InitAcceptSockets = False
    
End Function

Private Sub Command1_Click()
    Dim i As Integer
    For i = 0 To 29
        If WS(i).State <> 0 Then
            WS(i).SendData "#T"
            WS(i).Close
        End If
    Next i
End Sub




Private Sub Command3_Click()
    Dim i As Integer
    i = List1.ListIndex
    WS(i).Close
    
End Sub

Private Sub Command2_Click()
    Dim i As Integer
    i = List2.ListIndex
    WS(i).Close
    
End Sub

Private Sub Command4_Click()
    WS(1).SendData "Hello"
End Sub

Private Sub Form_Load()
    WS2.LocalPort = 80
    WS2.Listen
    
    If Not InitAcceptSockets Then
        MsgBox "CATOSTROPHIC ERROR: Can't dimention socket array!", vbCritical, "Error"
        End
    End If
    
    txtDebug = "Server is listening on port 80 for incoming connections" & vbNewLine

End Sub

Private Sub List2_Click()
    Picture1.Cls
    On Error Resume Next
    Picture1.Print "USER #: " & List2.ListIndex + 15
    Picture1.Print "Remote Host:    " & WS(List2.ListIndex + 15).RemoteHost
    Picture1.Print "Bytes Received: " & WS(List2.ListIndex + 15).BytesReceived
    Picture1.Print "Remote IP:      " & WS(List2.ListIndex + 15).RemoteHostIP
End Sub

Private Sub List1_Click()
    Picture1.Cls
    On Error Resume Next
    Picture1.Print "USER #: " & List1.ListIndex
    Picture1.Print "Remote Host:    " & WS(List1.ListIndex + 1).RemoteHost
    Picture1.Print "Bytes Received: " & WS(List1.ListIndex + 1).BytesReceived
    Picture1.Print "Remote IP:      " & WS(List1.ListIndex + 1).RemoteHostIP
End Sub

Private Sub Timer1_Timer()
    
    Dim li1 As Integer
    Dim li2 As Integer
    Dim i As Integer
    
    li1 = List1.ListIndex
    li2 = List2.ListIndex
    
    List2.Clear
    List1.Clear
    
    For i = 0 To 14
        If sockets(i) = True Then
            List1.AddItem "Socket: " & i & "  " & sockets(i) & "  IP: " & WS(i).RemoteHostIP
        Else
            List1.AddItem "Socket: " & i & "  " & sockets(i)
        End If
    Next i
    
    For i = 15 To 29
        If sockets(i) = True Then
            List2.AddItem "Socket: " & i & "  " & sockets(i) & "  IP: " & WS(i).RemoteHostIP
        Else
            List2.AddItem "Socket: " & i & "  " & sockets(i)
        End If
    Next i
    
    List1.ListIndex = li1
    List2.ListIndex = li2
    
End Sub


Private Sub WS_Close(Index As Integer)
    sockets(Index) = False
    WS(Index).Close
    txtDebug = txtDebug & vbNewLine & "Socket: " & Index & " has disconnected from the server."
End Sub

Private Sub WS_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim temp As String
    WS(Index).GetData temp
    txtDebug = txtDebug & vbNewLine & WS(Index).RemoteHostIP & " " & Index & ": Sent request: " & temp & vbNewLine
    Dim updatelen As String
    updatelen = FileLen(App.Path & "\update.cor")
    Select Case temp
        Case Is = "U"
        'request update
            WS(Index).SendData "#D"
        Case Is = "SR"
            WS(Index).SendData "*" & updatelen
        Case Else
            If Val(temp) > 0 Then
                Dim nv As String
                Open App.Path & "\newversion.inf" For Input As #1
                    Do Until EOF(1)
                        Input #1, nv
                    Loop
                    If Val(nv) > Val(temp) Then
                        WS(Index).SendData "#UA"
                    End If
                Close 1
            End If
    End Select
End Sub


Private Sub WS2_Close()
    WS2.Close
    WS2.Listen
End Sub

Private Sub WS2_ConnectionRequest(ByVal requestID As Long)
    Dim free As Integer
    free = GetFreeSocket
    If free <> 0 Then
        sockets(free) = True
        WS(free).Accept requestID
        WS2.Close
        WS2.Listen
        DoEvents
        Open App.Path & "\IPLOG.LOG" For Append As #1
            Write #1, WS(free).RemoteHostIP & "     " & Date & "      " & Time
        Close 1
    Else
        WS2.Accept requestID
        DoEvents
        WS2.SendData "#F"
        DoEvents
        WS2.Close
    End If
End Sub






CLIENT


HTML Code:
Dim username As String

Private Sub Command1_Click()
    If Text1 <> "" Then
        On Error GoTo handle
        Ws.Close
        Ws.Connect txthost, Val(txtport)
        Command1.Enabled = False
        username = Text1.Text
        Timer1.Enabled = True
    End If
    Exit Sub
handle:
    Timer1.Enabled = False
    MsgBox Err.Description
    Ws.Close
    Exit Sub
End Sub

Private Sub Command3_Click()
    Ws.SendData Text3
End Sub

Private Sub Form_Terminate()
    Ws.Close
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Ws.Close
End Sub


Private Sub Timer1_Timer()
    On Error GoTo handle
    Ws.SendData "U"
    unactive.Visible = False
    Active.Visible = True
    Timer1.Enabled = False
    Exit Sub
handle:
    MsgBox Err.Description
    Timer1.Enabled = False
    Command1.Enabled = True
    Exit Sub
End Sub

Private Sub Ws_Close()
    Active.Visible = False
    unactive.Visible = True
    Ws.Close
End Sub

Private Sub Ws_DataArrival(ByVal bytesTotal As Long)
    Dim strdata As String
    Dim Fsize As Long
    Ws.GetData strdata
    Text2 = Text2 & strdata
    Select Case strdata
        Case Is = "#D"
            Open App.Path & "/version.inf" For Input As #1
                Dim temp As String
                Do Until EOF(1)
                    Input #1, temp
                Loop
                Ws.SendData temp
                
            Close 1
        Case Is = "#UA"
            MsgBox "Update found... downloading..."
            Ws.SendData "SR"
        Case Else
            If Mid(temp, 1, 1) = "*" Then
                MsgBox "Update size = " & Mid(temp, 2, Len(temp) - 1) / 8 & " bytes"
                Fsize = Val(Mid(temp, 2, Len(temp) - 1))
            Else
            
            End If
                
    End Select
                
End Sub

lets clear up those command buttons... (images by www.imageshack.us)

for compresses source code in .vbp format, email me and ill send it to you.

http://img179.exs.cx/img179/3404/client1ek.jpg



thanks for the help.

http://img179.exs.cx/img179/2769/server2bb.jpg

Last edited by 1cemage; 02-02-2005 at 09:37 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please Winsock nub, need help please
Winsock nub, need help please
Winsock nub, need help please
 
Winsock nub, need help please
Winsock nub, need help please
 
-->