⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmclient.frm

📁 简单的vb聊天软件
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmClient 
   Caption         =   "TCP Client =>Download more : www.vivekpatel.cjb.net"
   ClientHeight    =   3420
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5895
   LinkTopic       =   "Form1"
   ScaleHeight     =   3420
   ScaleWidth      =   5895
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox lstMsg 
      Height          =   2595
      Left            =   0
      TabIndex        =   2
      Top             =   0
      Width           =   5775
   End
   Begin VB.TextBox txtmsg 
      Height          =   495
      Left            =   0
      TabIndex        =   1
      Top             =   2760
      Width           =   4575
   End
   Begin VB.CommandButton cmdSend 
      Caption         =   "Send"
      Default         =   -1  'True
      Height          =   495
      Left            =   4680
      TabIndex        =   0
      Top             =   2760
      Width           =   1095
   End
   Begin MSWinsockLib.Winsock tcpClient 
      Left            =   0
      Top             =   2520
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
End
Attribute VB_Name = "frmClient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'****************************************************
'Description : This is a Client side chat application
'               which will request to server application
'               server will accept request and establish connection with
'               it to allow message passing (chating).
' Author     : Vivek Patel.
' Contact    : www.vivekpatel.cjb.net
'              vivek_patel9@rediffmail.com
'****************************************************


'****************************************
' CONTROLs Used in Chat System are
' 1) lstMsg (ListBox)=> To display easily chat messages.
' 2) txtMsg (TextBox)=> To type data to be send to client.
' 3) cmdSend (Command Btn) => Btn., which when press sends data to clients computer.
' 4) tcpServer (Winsock control) => (ActiveX control added from components) which is used to comunicate between computers on network.
'----------------------------------------
' Note : I have used same controls in both client and server and also used same name except.
'        tcpServer for Server winsock control and tcpClient for client winsock control.
'****************************************


Option Explicit


'It makes Client request to server and thus
'Establish connection.
Private Sub Form_Load()
    Dim ipStr, portStr As String
    'Enter IP Address of Server Computer. (eg : 192.168.1.5 here network address is 192.168 and host address is 1.5)
    'Tip : to find server IP address type command : ipconfig on dos prompt.
    'by entering server IP Address you will be able to connect to server computer.
    'TIP to taste software on Single PC [Enter  : localhost     in inputBox]
    ipStr = InputBox("Enter the IP to connect to (eg : 192.168.1.5)")
    
    'Enter in inputBox the service no. it can be any valid string.
    'eg : 1234 (It is mandatory that service no. of client and server computer must be same to establish connection)
    portStr = InputBox("Enter the port to use (eg : 1234)")
    
    'Call connect method to establish connection
    tcpClient.Connect ipStr, portStr
End Sub


'It is used to set default focus to textbox.
'As unless form is visible it cannot set focus to any of its control
'and so i have used Activate event to set textbox focus
Private Sub Form_Activate()
    'to set default focus to textbox
    txtmsg.SetFocus
End Sub


'command btn when pressed will send text message to server
'Its default property is set to True (which means its code
'will executed on pressing enter that is here will send data
'on just pressing enter.)
Private Sub cmdSend_Click()
    Dim strdata As String
    strdata = "Client : " & txtmsg.Text
    'SendData method is used to send data.
    tcpClient.SendData strdata
    lstMsg.AddItem strdata 'adding send data into listbox to display it.
    txtmsg.Text = "" 'Making textbox clear
End Sub

'Whenever data is recieved this event occurs.
'Thus we can retrieve data just by invoking "GetData" method within it.
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
    Dim strdata As String
    'storing recieved data in strdata
    tcpClient.GetData strdata
    lstMsg.AddItem strdata 'displaying this data by adding it into listbox
End Sub


'Event occur when trying to close form
Private Sub Form_Unload(Cancel As Integer)
    tcpClient.Close
    
    MsgBox "Programmed By : Vivek Patel" & vbCrLf & _
            "Website : www.vivekpatel.cjb.net" & vbCrLf & _
            "Email : vivek_patel9@rediffmail.com", , "Simple Chat System"
End Sub










'****************************************************
'Description : This is a Client side chat application
'               which will request to server application
'               server will accept request and establish connection with
'               it to allow message passing (chating).
' Author     : Vivek Patel.
' Contact    : www.vivekpatel.cjb.net
'              vivek_patel9@rediffmail.com
'****************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -