Winsock SendData Problem 
Author Message
 Winsock SendData Problem

I have a vb6 winsock server app that works as a simple chat system.  It
listens to a particular port and as soon as a request for connection, it
goes it the pool of socket to find a free socket.  Then accept the
connection to the free socket found.

I basically use the telnet client that comes with windows as my client.
Telnet to my server ip at a particular port.  It works great if I have only
2 users.  As soon as I have more users, the text from one user reaches only
the more recent connected user.  The rest do not receive anything at all
until they hit the SPACE BAR.

My question is does it has anything to do with my server app or it's simply
the telnet client limitation?  Thank you.

Wooi.

The following is my code:
****************************************************************
Option Explicit
Const DefaultUserName = "EMPTY"
Const DefaultIP = "0.0.0.0"
Const MaxUser = 10
Private bUsed(MaxUser) As Boolean
Private sUsers(MaxUser) As String
Private wsUsers(MaxUser) As Winsock
Private sIP(MaxUser) As String
Private sResult(MaxUser) As String
Private Sub cmdExit_Click()
    Unload Me
End Sub
Private Sub Form_Load()
    Dim i As Integer

    For i = 1 To MaxUser
        'load sockets
        Load wsChat(i)
        wsChat(i).LocalPort = 0
        Set wsUsers(i) = wsChat(i)

        'assign users to default value
        sUsers(i) = DefaultUserName
    Next
    wsChat(0).Listen
End Sub

Private Sub wsChat_Close(Index As Integer)
    wsChat(Index).Close
    LogOff Index
End Sub

Private Sub wsChat_ConnectionRequest(Index As Integer, ByVal requestID As
Long)
    Dim i As Integer

    If Index <> 0 Then
        Exit Sub
    End If

    If Not IsFull Then
        i = GetSocket()
        bUsed(i) = True
        wsChat(i).Accept requestID
        wsChat(i).SendData "Welcome to the webfoot simple chat system." &
vbCrLf
        Logon i, wsChat(0).RemoteHostIP
    End If

End Sub
Private Function GetSocket() As Integer
    Dim i As Integer

    For i = 1 To MaxUser
        If Not bUsed(i) Then
            GetSocket = i
            Exit Function
        End If
    Next
End Function
Private Function IsFull() As Boolean
    Dim i As Integer

    For i = 1 To MaxUser
        If Not bUsed() Then
            IsFull = False
            Exit Function
        End If
    Next
    IsFull = True
End Function

Private Sub wsChat_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim sData As String
    Dim sChar As String

    Dim lCount As Long

    ' pull the data off the socket
    wsChat(Index).GetData sData, vbString, bytesTotal
    wsChat(Index).SendData sData

    ' loop through the data, appending it to the command buffer until
    '  you hit a crlf; crlf indicates a complete command
    For lCount = 1 To Len(sData)

        sChar = Mid(sData, lCount, 1)

        If sChar <> Chr(10) And sChar <> Chr(13) Then
            sResult(Index) = sResult(Index) & sChar
        ElseIf sChar = Chr(10) Then
            If Mid(sResult(Index), 1, 1) = "/" Then
                ProcessCommand Index, sResult(Index)
                sResult(Index) = ""
            Else
                ProcessText Index, sResult(Index)
                sResult(Index) = ""
            End If
        End If

    Next lCount

End Sub
Private Sub ProcessCommand(Index As Integer, Data As String)
    If UCase(Mid(Data, 2, 5)) = "LOGON" Then
        Logon Index, Mid(Data, 8)
    ElseIf UCase(Mid(Data, 2, 3)) = "WHO" Then
        wsChat(Index).SendData GetUsers & vbCrLf
    ElseIf UCase(Mid(Data, 2, 4)) = "HELP" Then
        wsChat(Index).SendData GetHelp & vbCrLf
    Else
        wsChat(Index).SendData "Unkwown command" & vbCrLf
    End If
End Sub
Private Sub ProcessText(Index As Integer, Data As String)
    Dim i As Integer

    If sUsers(Index) = DefaultUserName Then
        wsChat(Index).SendData "You have not identified yourself yet." &
vbCrLf
        wsChat(Index).Close
        Exit Sub
    End If

    ListChat.AddItem "<" & sUsers(Index) & "> " & Data

    For i = 1 To MaxUser
        If bUsed(i) And i <> Index Then
            wsUsers(i).SendData "<" & sUsers(Index) & "> " & Data & vbCrLf
        End If
    Next
End Sub
Private Sub Logon(Index As Integer, Data As String)
    Dim i As Integer

    sUsers(Index) = Data
    sIP(Index) = wsChat(Index).RemoteHostIP
    wsChat(Index).SendData "You are now logged in as " & Data & vbCrLf

    ListUser.Clear
    For i = 1 To MaxUser
        If bUsed(i) Then
            ListUser.AddItem sUsers(i)
        End If
    Next
End Sub
Private Sub LogOff(Index As Integer)
    Dim i As Integer

    sUsers(Index) = DefaultUserName
    sIP(Index) = DefaultIP
    bUsed(Index) = False

    ListUser.Clear
    For i = 1 To MaxUser
        If bUsed(i) Then
            ListUser.AddItem sUsers(i)
        End If
    Next
End Sub
Private Function GetUsers() As String
    Dim i As Integer
    Dim sReturn As String

    sReturn = ""

    For i = 1 To MaxUser
        If bUsed(i) Then
            sReturn = sReturn & sUsers(i) & " "
        End If
    Next
    GetUsers = sReturn
End Function
Private Function GetHelp() As String
    Dim sReturn As String

    sReturn = vbNewLine
    sReturn = sReturn & "**HELP***" & vbNewLine
    sReturn = sReturn & "/LOGON yournick - Logon as yournick" & vbNewLine
    sReturn = sReturn & "/WHO - List all connected users" & vbNewLine
    sReturn = sReturn & "/HELP - Display this menu" & vbNewLine

    GetHelp = sReturn
End Function
********************************



Fri, 10 May 2002 03:00:00 GMT  
 Winsock SendData Problem
That is a problem of the Winsock control. You have to add many DOEVENTS as
you can to avoid this.

The way a have chosed is to use sockettools from Catalyst.

--

                       \\~ ~//

        ----------o00o-(_)-o00o-------------
Mauricio Mrquez Anze
United Nations Development Programme

Quote:

> I have a vb6 winsock server app that works as a simple chat system.  It
> listens to a particular port and as soon as a request for connection, it
> goes it the pool of socket to find a free socket.  Then accept the
> connection to the free socket found.

> I basically use the telnet client that comes with windows as my client.
> Telnet to my server ip at a particular port.  It works great if I have
only
> 2 users.  As soon as I have more users, the text from one user reaches
only
> the more recent connected user.  The rest do not receive anything at all
> until they hit the SPACE BAR.

> My question is does it has anything to do with my server app or it's
simply
> the telnet client limitation?  Thank you.

> Wooi.

> The following is my code:
> ****************************************************************
> Option Explicit
> Const DefaultUserName = "EMPTY"
> Const DefaultIP = "0.0.0.0"
> Const MaxUser = 10
> Private bUsed(MaxUser) As Boolean
> Private sUsers(MaxUser) As String
> Private wsUsers(MaxUser) As Winsock
> Private sIP(MaxUser) As String
> Private sResult(MaxUser) As String
> Private Sub cmdExit_Click()
>     Unload Me
> End Sub
> Private Sub Form_Load()
>     Dim i As Integer

>     For i = 1 To MaxUser
>         'load sockets
>         Load wsChat(i)
>         wsChat(i).LocalPort = 0
>         Set wsUsers(i) = wsChat(i)

>         'assign users to default value
>         sUsers(i) = DefaultUserName
>     Next
>     wsChat(0).Listen
> End Sub

> Private Sub wsChat_Close(Index As Integer)
>     wsChat(Index).Close
>     LogOff Index
> End Sub

> Private Sub wsChat_ConnectionRequest(Index As Integer, ByVal requestID As
> Long)
>     Dim i As Integer

>     If Index <> 0 Then
>         Exit Sub
>     End If

>     If Not IsFull Then
>         i = GetSocket()
>         bUsed(i) = True
>         wsChat(i).Accept requestID
>         wsChat(i).SendData "Welcome to the webfoot simple chat system." &
> vbCrLf
>         Logon i, wsChat(0).RemoteHostIP
>     End If

> End Sub
> Private Function GetSocket() As Integer
>     Dim i As Integer

>     For i = 1 To MaxUser
>         If Not bUsed(i) Then
>             GetSocket = i
>             Exit Function
>         End If
>     Next
> End Function
> Private Function IsFull() As Boolean
>     Dim i As Integer

>     For i = 1 To MaxUser
>         If Not bUsed() Then
>             IsFull = False
>             Exit Function
>         End If
>     Next
>     IsFull = True
> End Function

> Private Sub wsChat_DataArrival(Index As Integer, ByVal bytesTotal As Long)
>     Dim sData As String
>     Dim sChar As String

>     Dim lCount As Long

>     ' pull the data off the socket
>     wsChat(Index).GetData sData, vbString, bytesTotal
>     wsChat(Index).SendData sData

>     ' loop through the data, appending it to the command buffer until
>     '  you hit a crlf; crlf indicates a complete command
>     For lCount = 1 To Len(sData)

>         sChar = Mid(sData, lCount, 1)

>         If sChar <> Chr(10) And sChar <> Chr(13) Then
>             sResult(Index) = sResult(Index) & sChar
>         ElseIf sChar = Chr(10) Then
>             If Mid(sResult(Index), 1, 1) = "/" Then
>                 ProcessCommand Index, sResult(Index)
>                 sResult(Index) = ""
>             Else
>                 ProcessText Index, sResult(Index)
>                 sResult(Index) = ""
>             End If
>         End If

>     Next lCount

> End Sub
> Private Sub ProcessCommand(Index As Integer, Data As String)
>     If UCase(Mid(Data, 2, 5)) = "LOGON" Then
>         Logon Index, Mid(Data, 8)
>     ElseIf UCase(Mid(Data, 2, 3)) = "WHO" Then
>         wsChat(Index).SendData GetUsers & vbCrLf
>     ElseIf UCase(Mid(Data, 2, 4)) = "HELP" Then
>         wsChat(Index).SendData GetHelp & vbCrLf
>     Else
>         wsChat(Index).SendData "Unkwown command" & vbCrLf
>     End If
> End Sub
> Private Sub ProcessText(Index As Integer, Data As String)
>     Dim i As Integer

>     If sUsers(Index) = DefaultUserName Then
>         wsChat(Index).SendData "You have not identified yourself yet." &
> vbCrLf
>         wsChat(Index).Close
>         Exit Sub
>     End If

>     ListChat.AddItem "<" & sUsers(Index) & "> " & Data

>     For i = 1 To MaxUser
>         If bUsed(i) And i <> Index Then
>             wsUsers(i).SendData "<" & sUsers(Index) & "> " & Data & vbCrLf
>         End If
>     Next
> End Sub
> Private Sub Logon(Index As Integer, Data As String)
>     Dim i As Integer

>     sUsers(Index) = Data
>     sIP(Index) = wsChat(Index).RemoteHostIP
>     wsChat(Index).SendData "You are now logged in as " & Data & vbCrLf

>     ListUser.Clear
>     For i = 1 To MaxUser
>         If bUsed(i) Then
>             ListUser.AddItem sUsers(i)
>         End If
>     Next
> End Sub
> Private Sub LogOff(Index As Integer)
>     Dim i As Integer

>     sUsers(Index) = DefaultUserName
>     sIP(Index) = DefaultIP
>     bUsed(Index) = False

>     ListUser.Clear
>     For i = 1 To MaxUser
>         If bUsed(i) Then
>             ListUser.AddItem sUsers(i)
>         End If
>     Next
> End Sub
> Private Function GetUsers() As String
>     Dim i As Integer
>     Dim sReturn As String

>     sReturn = ""

>     For i = 1 To MaxUser
>         If bUsed(i) Then
>             sReturn = sReturn & sUsers(i) & " "
>         End If
>     Next
>     GetUsers = sReturn
> End Function
> Private Function GetHelp() As String
>     Dim sReturn As String

>     sReturn = vbNewLine
>     sReturn = sReturn & "**HELP***" & vbNewLine
>     sReturn = sReturn & "/LOGON yournick - Logon as yournick" & vbNewLine
>     sReturn = sReturn & "/WHO - List all connected users" & vbNewLine
>     sReturn = sReturn & "/HELP - Display this menu" & vbNewLine

>     GetHelp = sReturn
> End Function
> ********************************



Sat, 11 May 2002 03:00:00 GMT  
 Winsock SendData Problem
but its not free is?



Quote:
> That is a problem of the Winsock control. You have to add many DOEVENTS as
> you can to avoid this.

> The way a have chosed is to use sockettools from Catalyst.

> --

>                        \\~ ~//

>         ----------o00o-(_)-o00o-------------
> Mauricio Mrquez Anze
> United Nations Development Programme

> > I have a vb6 winsock server app that works as a simple chat system.  It
> > listens to a particular port and as soon as a request for connection, it
> > goes it the pool of socket to find a free socket.  Then accept the
> > connection to the free socket found.

> > I basically use the telnet client that comes with windows as my client.
> > Telnet to my server ip at a particular port.  It works great if I have
> only
> > 2 users.  As soon as I have more users, the text from one user reaches
> only
> > the more recent connected user.  The rest do not receive anything at all
> > until they hit the SPACE BAR.

> > My question is does it has anything to do with my server app or it's
> simply
> > the telnet client limitation?  Thank you.

> > Wooi.

> > The following is my code:
> > ****************************************************************
> > Option Explicit
> > Const DefaultUserName = "EMPTY"
> > Const DefaultIP = "0.0.0.0"
> > Const MaxUser = 10
> > Private bUsed(MaxUser) As Boolean
> > Private sUsers(MaxUser) As String
> > Private wsUsers(MaxUser) As Winsock
> > Private sIP(MaxUser) As String
> > Private sResult(MaxUser) As String
> > Private Sub cmdExit_Click()
> >     Unload Me
> > End Sub
> > Private Sub Form_Load()
> >     Dim i As Integer

> >     For i = 1 To MaxUser
> >         'load sockets
> >         Load wsChat(i)
> >         wsChat(i).LocalPort = 0
> >         Set wsUsers(i) = wsChat(i)

> >         'assign users to default value
> >         sUsers(i) = DefaultUserName
> >     Next
> >     wsChat(0).Listen
> > End Sub

> > Private Sub wsChat_Close(Index As Integer)
> >     wsChat(Index).Close
> >     LogOff Index
> > End Sub

> > Private Sub wsChat_ConnectionRequest(Index As Integer, ByVal requestID
As
> > Long)
> >     Dim i As Integer

> >     If Index <> 0 Then
> >         Exit Sub
> >     End If

> >     If Not IsFull Then
> >         i = GetSocket()
> >         bUsed(i) = True
> >         wsChat(i).Accept requestID
> >         wsChat(i).SendData "Welcome to the webfoot simple chat system."
&
> > vbCrLf
> >         Logon i, wsChat(0).RemoteHostIP
> >     End If

> > End Sub
> > Private Function GetSocket() As Integer
> >     Dim i As Integer

> >     For i = 1 To MaxUser
> >         If Not bUsed(i) Then
> >             GetSocket = i
> >             Exit Function
> >         End If
> >     Next
> > End Function
> > Private Function IsFull() As Boolean
> >     Dim i As Integer

> >     For i = 1 To MaxUser
> >         If Not bUsed() Then
> >             IsFull = False
> >             Exit Function
> >         End If
> >     Next
> >     IsFull = True
> > End Function

> > Private Sub wsChat_DataArrival(Index As Integer, ByVal bytesTotal As
Long)
> >     Dim sData As String
> >     Dim sChar As String

> >     Dim lCount As Long

> >     ' pull the data off the socket
> >     wsChat(Index).GetData sData, vbString, bytesTotal
> >     wsChat(Index).SendData sData

> >     ' loop through the data, appending it to the command buffer until
> >     '  you hit a crlf; crlf indicates a complete command
> >     For lCount = 1 To Len(sData)

> >         sChar = Mid(sData, lCount, 1)

> >         If sChar <> Chr(10) And sChar <> Chr(13) Then
> >             sResult(Index) = sResult(Index) & sChar
> >         ElseIf sChar = Chr(10) Then
> >             If Mid(sResult(Index), 1, 1) = "/" Then
> >                 ProcessCommand Index, sResult(Index)
> >                 sResult(Index) = ""
> >             Else
> >                 ProcessText Index, sResult(Index)
> >                 sResult(Index) = ""
> >             End If
> >         End If

> >     Next lCount

> > End Sub
> > Private Sub ProcessCommand(Index As Integer, Data As String)
> >     If UCase(Mid(Data, 2, 5)) = "LOGON" Then
> >         Logon Index, Mid(Data, 8)
> >     ElseIf UCase(Mid(Data, 2, 3)) = "WHO" Then
> >         wsChat(Index).SendData GetUsers & vbCrLf
> >     ElseIf UCase(Mid(Data, 2, 4)) = "HELP" Then
> >         wsChat(Index).SendData GetHelp & vbCrLf
> >     Else
> >         wsChat(Index).SendData "Unkwown command" & vbCrLf
> >     End If
> > End Sub
> > Private Sub ProcessText(Index As Integer, Data As String)
> >     Dim i As Integer

> >     If sUsers(Index) = DefaultUserName Then
> >         wsChat(Index).SendData "You have not identified yourself yet." &
> > vbCrLf
> >         wsChat(Index).Close
> >         Exit Sub
> >     End If

> >     ListChat.AddItem "<" & sUsers(Index) & "> " & Data

> >     For i = 1 To MaxUser
> >         If bUsed(i) And i <> Index Then
> >             wsUsers(i).SendData "<" & sUsers(Index) & "> " & Data &
vbCrLf
> >         End If
> >     Next
> > End Sub
> > Private Sub Logon(Index As Integer, Data As String)
> >     Dim i As Integer

> >     sUsers(Index) = Data
> >     sIP(Index) = wsChat(Index).RemoteHostIP
> >     wsChat(Index).SendData "You are now logged in as " & Data & vbCrLf

> >     ListUser.Clear
> >     For i = 1 To MaxUser
> >         If bUsed(i) Then
> >             ListUser.AddItem sUsers(i)
> >         End If
> >     Next
> > End Sub
> > Private Sub LogOff(Index As Integer)
> >     Dim i As Integer

> >     sUsers(Index) = DefaultUserName
> >     sIP(Index) = DefaultIP
> >     bUsed(Index) = False

> >     ListUser.Clear
> >     For i = 1 To MaxUser
> >         If bUsed(i) Then
> >             ListUser.AddItem sUsers(i)
> >         End If
> >     Next
> > End Sub
> > Private Function GetUsers() As String
> >     Dim i As Integer
> >     Dim sReturn As String

> >     sReturn = ""

> >     For i = 1 To MaxUser
> >         If bUsed(i) Then
> >             sReturn = sReturn & sUsers(i) & " "
> >         End If
> >     Next
> >     GetUsers = sReturn
> > End Function
> > Private Function GetHelp() As String
> >     Dim sReturn As String

> >     sReturn = vbNewLine
> >     sReturn = sReturn & "**HELP***" & vbNewLine
> >     sReturn = sReturn & "/LOGON yournick - Logon as yournick" &
vbNewLine
> >     sReturn = sReturn & "/WHO - List all connected users" & vbNewLine
> >     sReturn = sReturn & "/HELP - Display this menu" & vbNewLine

> >     GetHelp = sReturn
> > End Function
> > ********************************



Mon, 13 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. winsock senddata problem/question

2. Winsock.SendData Problem

3. VB6: Winsock senddata problem - help!

4. Visual Basic Winsock senddata problem

5. WInsock SendData problem HELP

6. Winsock SendData problems

7. Winsock SendData Problem?

8. Winsock SendData problem

9. Winsock SendData problems

10. Winsock SendData Problem?

11. Winsock senddata problem!

12. Easy winsock.senddata problem

 

 
Powered by phpBB® Forum Software