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

📄 form1.frm

📁 the Customer programs in vb for chat
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5400
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8190
   LinkTopic       =   "Form1"
   ScaleHeight     =   5400
   ScaleWidth      =   8190
   StartUpPosition =   3  'Windows Default
   Begin MSWinsockLib.Winsock Winsock2 
      Index           =   0
      Left            =   4890
      Top             =   3690
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   1920
      Top             =   3540
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   525
      Left            =   2730
      TabIndex        =   3
      Top             =   2310
      Width           =   1245
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   525
      Left            =   690
      TabIndex        =   2
      Top             =   2280
      Width           =   1245
   End
   Begin VB.TextBox Text2 
      Height          =   405
      Left            =   4050
      TabIndex        =   1
      Text            =   "2000"
      Top             =   1500
      Width           =   885
   End
   Begin VB.TextBox Text1 
      Height          =   915
      Left            =   540
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   300
      Width           =   4485
   End
   Begin MSWinsockLib.Winsock Winsock2 
      Index           =   1
      Left            =   4980
      Top             =   4140
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
  Winsock1.Close ' Cerramos el winsock para no dar problemas
  Winsock1.LocalPort = Text2.Text 'El puerto a esuchar es el que introduzcamos en text3.text
  Winsock1.Listen ' dejamos a la esucha el winsock
End Sub

Private Sub Form_Load()

End Sub

Private Sub Winsock1_ConnectionRequest(ByVal RequestID As Long) ' Es el codigo de antes
  Dim socketCreado As Integer


  socketCreado = CrearSocket
  Winsock2(socketCreado).Accept RequestID

  Text1.Text = Text1.Text & vbNewLine & "Petici髇 Aceptada Socket num " & socketCreado & " interactuando"
End Sub
Private Function CrearSocket() As Integer

  Dim Sockets As Integer 'Variable que cojera el numero de sockets
  Dim x As Integer 'Contara los sockets que ai
  
  Sockets = Winsock2.UBound 'Nos vamos hasta el final de los winsock para ver los que tenemos
  
  For x = 0 To Sockets ' Recorremos todos los winsocks
    If Winsock2(x).State = sckClosed Then 'Comprovamos los sockets inactivos
      CrearSocket = x 'Si winsock2 esta inactivo lo utilizamos
      Exit Function 'Salimos de la funcion
    End If
  Next
  MsgBox Sockets + 1
  Load Winsock2(Sockets + 1) 'En el caso que no tengamos sockets inactivos, crea un socket
  
  CrearSocket = Winsock2.UBound 'Pasamos el numero de sockets actuales a CrearSocket
End Function

⌨️ 快捷键说明

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