VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmChat 
   Caption         =   "Chat - Shahid Thaika"
   ClientHeight    =   7140
   ClientLeft      =   4425
   ClientTop       =   1080
   ClientWidth     =   3840
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   7140
   ScaleWidth      =   3840
   StartUpPosition =   2  'CenterScreen
   Begin VB.CheckBox chkLock 
      Caption         =   "Locked"
      Height          =   495
      Left            =   1200
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   6600
      Value           =   1  'Checked
      Width           =   1215
   End
   Begin MSWinsockLib.Winsock Sock 
      Left            =   120
      Top             =   6600
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton cmdSend 
      Caption         =   "Send"
      Default         =   -1  'True
      Height          =   495
      Left            =   2520
      TabIndex        =   2
      Top             =   6600
      Width           =   1215
   End
   Begin VB.TextBox txtSend 
      Height          =   1215
      Left            =   120
      MultiLine       =   -1  'True
      TabIndex        =   1
      Top             =   5280
      Width           =   3615
   End
   Begin VB.TextBox txtChatWin 
      Height          =   5055
      Left            =   120
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   120
      Width           =   3615
   End
End
Attribute VB_Name = "frmChat"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim RemoteHost As String
Dim RemotePort As Integer
Dim LocalPort As Integer
Dim myName As String

Private Sub chkLock_Click()
txtChatWin.Locked = chkLock.Value 'Sets the Main Text Box of chat to readonly/editable mode
End Sub

Private Sub cmdSend_Click()
On Error Resume Next
'Code for sending text data copied from 'vbworld.com' - Karl
'Know problem... The first time button is clicked, it does not send data
'data is sent only from the second click of button

Sock.Close

Sock.RemoteHost = RemoteHost
Sock.RemotePort = RemotePort

Sock.Connect

Do Until Sock.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
Loop

Sock.SendData (myName & " says: " & txtSend & vbCrLf)

txtChatWin = txtChatWin & myName & " says: " & txtSend & vbCrLf

txtSend = "" 'Reset send chat Text Box

'Help me here please.

'Sock.Close
'Sock.LocalPort = LocalPort
'Sock.Listen

End Sub

Private Sub Form_Load()
    RemoteHost = InputBox("Enter the IP Address or Computer name of remote computer. 'Exit' to exit the application.", "Remote Host", "192.168.0.")
    
    If RemoteHost = "exit" Then
        Unload frmWait
        Exit Sub
    End If
    
    RemotePort = InputBox("Enter the Remote Port for sending chat. Port must not be in use. This is also the Local Port of other machine. Eg: 1001", "Remote Port", "1001")
    
    LocalPort = InputBox("Enter the Local Port for receiving chat. Can't be same as Port for sending. This is also the Remote Port of other machine. Eg: 1002", "Local Port", "1002")
    
    myName = InputBox("What is your Nick name", "Nick Name", "Guest")
    
Sock.LocalPort = LocalPort
Sock.Listen
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Sock.Close
End
End Sub

Private Sub mnuSetup_Click()
txtSend.Enabled = True
cmdSend.Enabled = True
End Sub

Private Sub Sock_ConnectionRequest(ByVal requestID As Long)
If Sock.State <> sckClosed Then Sock.Close
Sock.Accept requestID
End Sub

Private Sub Sock_DataArrival(ByVal bytesTotal As Long)
Dim strIncoming As String
Sock.GetData strIncoming

txtChatWin = txtChatWin & strIncoming

Sock.Close
Sock.LocalPort = LocalPort
Sock.Listen
End Sub
