[RESOLVED] IRC Chat Program Won't Connect
Hi, I am making an IRC Chat program with Visual Basic for general use between me and my friends and I would like to know why it isn't working. The problem is, when I type in an IP address into the corresponding textbox and click listen...then open up another version of the program and click Connect it does not connect...maybe it is something to do with the winsock code and the ip/port etc? I'm not sure...but here is the code I have got (thanks in advance):
Code:
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()
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
cmdsend.Enabled = True
cmdclose.Enabled = True
cmdlisten.Enabled = False
cmdconnect.Enabled = False
txtname.Enabled = False
End Sub
Private Sub AddText(ByVal text As String, ByRef Box As TextBox)
'Take the text box passed as a reference and
'add the "text" variable to it
Box.text = Box.text & text & vbCrLf
Box.SelStart = Len(Box.text)
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
wschat.Close
wschat.RemoteHost = txtip.text
wschat.RemotePort = 1234
wschat.Listen
cmdclose.Enabled = True
cmdlisten.Enabled = False
cmdconnect.Enabled = False
txtname.Enabled = False
AddText "----- Waiting for Connection -----", txtin
End Sub
Private Sub cmdsend_Click()
'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
Private Sub Form_Load()
End Sub
Private Sub wschat_Connect()
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 wschat_ConnectionRequest(ByVal requestID As Long)
wschat.Close
wschat.Accept requestID
'If the remote system requests a connection, accept it and connect
AddText "----- Connection Established -----" & vbCrLf, txtin
'Tell the user that the connection has been established
cmdsend.Enabled = True
txtname.Enabled = False
txtout.SetFocus
End Sub
Private Sub wschat_DataArrival(ByVal bytesTotal As Long)
Dim incoming As String
'Tell the Winsock control to place the incoming data into a string.
'Then call the function to print the data into the "Incoming Data" textbox.
wschat.GetData incoming
AddText incoming, 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
End Sub