Results 1 to 2 of 2

Thread: client/chat error

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    client/chat error

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdClose_Click()
    4.     'Disable the outgoing buttons and tell the user
    5.     'that the connection has been closed
    6.    
    7.     wsChat.Close
    8.     cmdClose.Enabled = False
    9.     cmdSend.Enabled = False
    10.     txtName.Enabled = True
    11.     cmdListen.Enabled = True
    12.     cmdConnect.Enabled = True
    13.     txtIn.text = "----- Connection Closed -----" & vbCrLf
    14. End Sub
    15.  
    16. Private Sub cmdConnect_Click()
    17.     'Before we can connect, we should check to see
    18.     'if there is an IP and name for the user.
    19.  
    20.     If txtIP.text = "" Or txtName.text = "" Then
    21.         MsgBox "You must enter both an IP and alias first!", vbCritical, "Error!"
    22.         txtName.SetFocus
    23.         Exit Sub
    24.     End If
    25.     On Error Resume Next
    26.  
    27.     'Connecting the IP that is placed in the txtIP.text value.
    28.  
    29.     wsChat.Close
    30.     wsChat.Connect txtIP.text, 1234
    31.    
    32.     cmdClose.Enabled = True
    33.     cmdListen.Enabled = False
    34.     cmdConnect.Enabled = False
    35.     txtName.Enabled = False
    36.    
    37. End Sub
    38.  
    39. Private Sub cmdListen_Click()
    40.     If txtName.text = "" Then
    41.         MsgBox "You must enter an alias first!", vbCritical, "Error!"
    42.         txtName.SetFocus
    43.         Exit Sub
    44.     End If
    45.  
    46.     'Place the local IP into this textbox and wait for a chat invitation.
    47.  
    48.     txtIP.text = wsChat.LocalIP
    49.     wsChat.Close
    50.     wsChat.LocalPort = 1234
    51.     wsChat.Listen
    52.     cmdClose.Enabled = True
    53.     cmdListen.Enabled = False
    54.     cmdConnect.Enabled = False
    55.     txtName.Enabled = False
    56.     AddText "----- Waiting for Connection -----", txtIn
    57. End Sub
    58.  
    59. Private Sub wsChat_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    60.     If Number <> 0 Then
    61.         AddText "----- Error [" & Description & "] -----" & vbCrLf, txtIn
    62.         Call cmdClose_Click
    63.     End If
    64.    
    65.     Do
    66.     DoEvents
    67.     Loop Until wsChat.State = sckConnected Or wsChat.State = sckError
    68.    
    69.     If wsChat.State = sckConnected Then
    70.         'Tell the user that the connection has been established
    71.         AddText "----- Connection Established -----" & vbCrLf, txtIn
    72.         cmdSend.Enabled = True
    73.         txtName.Enabled = False
    74.         txtOut.SetFocus
    75.     Else
    76.         'Tell the user that the connection has been established
    77.         AddText "----- Connection Failed -----" & vbCrLf, txtIn
    78.     End If
    79. End Sub
    80.  
    81. Private Sub AddText(ByVal text As String, ByRef Box As TextBox)
    82.     Box.text = Box.text & text & vbCrLf
    83.     Box.SelStart = Len(Box.text)
    84.  
    85.     'Send the data to the remote user
    86.     wsChat.SendData "[" & txtName.text & "] " & txtOut.text
    87.     AddText "[" & txtName.text & "] " & txtOut.text, txtIn
    88.    
    89.     'Clear out typed text and refocus on the box
    90.     txtOut.text = ""
    91.     txtOut.SetFocus
    92. End Sub

    my problem is that when i click on the 'listen' button it gives me a error '40006 saying wrong connection or protocol state' and it highlights this line in the addtext function

    wsChat.SendData "[" & txtName.text & "] " & txtOut.text

    any ideas why

    i want my computer ip to act as the server, and make clients connect to this server so they can exchange messages

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: client/chat error

    Ok this is simple.

    You can send any data to a client until you are connected (ie the client has connected to you and you have accepted it)

    What is happening is you are setting up listening but no-one has connected so you have not made a connection hence you connot send data.

    This is what the error means.

    Pino

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