Pouncer
Nov 29th, 2005, 02:39 PM
Option Explicit
Private Sub cmdClose_Click()
'Disable the outgoing buttons and tell the user
'that the connection has been closed
wsChat.Close
cmdClose.Enabled = False
cmdSend.Enabled = False
txtName.Enabled = True
cmdListen.Enabled = True
cmdConnect.Enabled = True
txtIn.text = "----- Connection Closed -----" & vbCrLf
End Sub
Private Sub cmdConnect_Click()
'Before we can connect, we should check to see
'if there is an IP and name for the user.
If txtIP.text = "" Or txtName.text = "" Then
MsgBox "You must enter both an IP and alias first!", vbCritical, "Error!"
txtName.SetFocus
Exit Sub
End If
On Error Resume Next
'Connecting the IP that is placed in the txtIP.text value.
wsChat.Close
wsChat.Connect txtIP.text, 1234
cmdClose.Enabled = True
cmdListen.Enabled = False
cmdConnect.Enabled = False
txtName.Enabled = False
End Sub
Private Sub cmdListen_Click()
If txtName.text = "" Then
MsgBox "You must enter an alias first!", vbCritical, "Error!"
txtName.SetFocus
Exit Sub
End If
'Place the local IP into this textbox and wait for a chat invitation.
txtIP.text = wsChat.LocalIP
wsChat.Close
wsChat.LocalPort = 1234
wsChat.Listen
cmdClose.Enabled = True
cmdListen.Enabled = False
cmdConnect.Enabled = False
txtName.Enabled = False
AddText "----- Waiting for Connection -----", txtIn
End Sub
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)
If Number <> 0 Then
AddText "----- Error [" & Description & "] -----" & vbCrLf, txtIn
Call cmdClose_Click
End If
Do
DoEvents
Loop Until wsChat.State = sckConnected Or wsChat.State = sckError
If wsChat.State = sckConnected Then
'Tell the user that the connection has been established
AddText "----- Connection Established -----" & vbCrLf, txtIn
cmdSend.Enabled = True
txtName.Enabled = False
txtOut.SetFocus
Else
'Tell the user that the connection has been established
AddText "----- Connection Failed -----" & vbCrLf, txtIn
End If
End Sub
Private Sub AddText(ByVal text As String, ByRef Box As TextBox)
Box.text = Box.text & text & vbCrLf
Box.SelStart = Len(Box.text)
'Send the data to the remote user
wsChat.SendData "[" & txtName.text & "] " & txtOut.text
AddText "[" & txtName.text & "] " & txtOut.text, txtIn
'Clear out typed text and refocus on the box
txtOut.text = ""
txtOut.SetFocus
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 :confused:
i want my computer ip to act as the server, and make clients connect to this server so they can exchange messages
Private Sub cmdClose_Click()
'Disable the outgoing buttons and tell the user
'that the connection has been closed
wsChat.Close
cmdClose.Enabled = False
cmdSend.Enabled = False
txtName.Enabled = True
cmdListen.Enabled = True
cmdConnect.Enabled = True
txtIn.text = "----- Connection Closed -----" & vbCrLf
End Sub
Private Sub cmdConnect_Click()
'Before we can connect, we should check to see
'if there is an IP and name for the user.
If txtIP.text = "" Or txtName.text = "" Then
MsgBox "You must enter both an IP and alias first!", vbCritical, "Error!"
txtName.SetFocus
Exit Sub
End If
On Error Resume Next
'Connecting the IP that is placed in the txtIP.text value.
wsChat.Close
wsChat.Connect txtIP.text, 1234
cmdClose.Enabled = True
cmdListen.Enabled = False
cmdConnect.Enabled = False
txtName.Enabled = False
End Sub
Private Sub cmdListen_Click()
If txtName.text = "" Then
MsgBox "You must enter an alias first!", vbCritical, "Error!"
txtName.SetFocus
Exit Sub
End If
'Place the local IP into this textbox and wait for a chat invitation.
txtIP.text = wsChat.LocalIP
wsChat.Close
wsChat.LocalPort = 1234
wsChat.Listen
cmdClose.Enabled = True
cmdListen.Enabled = False
cmdConnect.Enabled = False
txtName.Enabled = False
AddText "----- Waiting for Connection -----", txtIn
End Sub
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)
If Number <> 0 Then
AddText "----- Error [" & Description & "] -----" & vbCrLf, txtIn
Call cmdClose_Click
End If
Do
DoEvents
Loop Until wsChat.State = sckConnected Or wsChat.State = sckError
If wsChat.State = sckConnected Then
'Tell the user that the connection has been established
AddText "----- Connection Established -----" & vbCrLf, txtIn
cmdSend.Enabled = True
txtName.Enabled = False
txtOut.SetFocus
Else
'Tell the user that the connection has been established
AddText "----- Connection Failed -----" & vbCrLf, txtIn
End If
End Sub
Private Sub AddText(ByVal text As String, ByRef Box As TextBox)
Box.text = Box.text & text & vbCrLf
Box.SelStart = Len(Box.text)
'Send the data to the remote user
wsChat.SendData "[" & txtName.text & "] " & txtOut.text
AddText "[" & txtName.text & "] " & txtOut.text, txtIn
'Clear out typed text and refocus on the box
txtOut.text = ""
txtOut.SetFocus
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 :confused:
i want my computer ip to act as the server, and make clients connect to this server so they can exchange messages