GroupWinsockListenTest.vbg - Winsock TCP C/S 网络程序编写 事例 - VB6 + Winsock - HackerJLY
prjWinsockListenTestServer.vbp - 服务器端
Type=Exe
Form=frmMain.frm
Reference=*/G{00020430-0000-0000-C000-000000000046}#2.0#0#C:/WINDOWS/system32/stdole2.tlb#OLE Automation
Object={248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0; MSWINSCK.OCX
IconForm="frmMain"
Startup="frmMain"
ExeName32="prjWinsockListenTestServer.exe"
Command32=""
Name="prjWinsockListenTestServer"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="http://blog.csdn.net/HackerJLY"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
frmMain.frm
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmMain
Caption = "prjWinsockListenTestServer"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtReceive
Height = 2535
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 480
Width = 4695
End
Begin MSWinsockLib.Winsock wskServer
Left = 0
Top = 0
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
With wskServer
.Protocol = sckTCPProtocol
.LocalPort = 6000
'.Bind , .LocalIP
.Listen
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
With wskServer
.Close
End With
End Sub
Private Sub wskServer_Close()
With wskServer
.Close
.Listen
End With
End Sub
Private Sub wskServer_ConnectionRequest(ByVal requestID As Long)
With wskServer
'--------------------------------------------------
If .State <> sckClosed Then
.Close
End If
'--------------------------------------------------
.Accept requestID
'--------------------------------------------------
.SendData "Welcome Visit !!!!" & Date & Time
End With
End Sub
Private Sub wskServer_DataArrival(ByVal bytesTotal As Long)
Dim strReceive As String
With wskServer
.GetData strReceive
txtReceive.Text = strReceive '& vbCrLf & .RemoteHost & .RemoteHostIP & .RemotePort
End With
End Sub
prjWinsockListenTestClient.vbp - 客户端
Type=Exe
Form=frmMain.frm
Reference=*/G{00020430-0000-0000-C000-000000000046}#2.0#0#C:/WINDOWS/system32/stdole2.tlb#OLE Automation
Object={248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0; MSWINSCK.OCX
IconForm="frmMain"
Startup="frmMain"
ExeName32="prjWinsockListenTestClient.exe"
Command32=""
Name="prjWinsockListenTestClient"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="http://blog.csdn.net/HackerJLY"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
frmMain.frm
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmMain
Caption = "prjWinsockListenTestClient"
ClientHeight = 6870
ClientLeft = 60
ClientTop = 345
ClientWidth = 4830
LinkTopic = "Form1"
ScaleHeight = 6870
ScaleWidth = 4830
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtReceive
Height = 2535
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 2
Top = 600
Width = 4695
End
Begin VB.CommandButton cmdSend
Caption = "cmdSend"
Height = 375
Left = 3360
TabIndex = 1
Top = 6240
Width = 1095
End
Begin VB.TextBox txtSend
Height = 2535
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 3480
Width = 4695
End
Begin MSWinsockLib.Winsock wskClient
Left = 0
Top = 0
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdSend_Click()
With wskClient
.SendData CStr(txtSend.Text)
End With
End Sub
Private Sub Form_Load()
With txtSend
.Text = "Connect Test" & Date & Time
End With
With wskClient
.Protocol = sckTCPProtocol
.RemoteHost = "127.0.0.1"
'.RemoteHost = "192.168.1.68"
'.RemoteHost = "192.168.1.108"
.RemotePort = 6000
.Connect
End With
End Sub
Private Sub wskClient_DataArrival(ByVal bytesTotal As Long)
Dim strReceive As String
With wskClient
.GetData strReceive
txtReceive.Text = strReceive '& vbCrLf & .RemoteHost & .RemoteHostIP & .RemotePort
End With
End Sub