Samuel Learning

  • 联系
  •  
  • 管理

文章分类(203)

  • 01 ASP/HTML(6)
  • 02 Script/CSS(16)
  • 03 C/C++
  • 04 XML(4)
  • 05 微软编程(26)
  • 06 J2EE(60)
  • 09 Linux(14)
  • 10 Database(27)
  • 11 报表打印
  • 12 打包安装(1)
  • 13 模式重构(2)
  • 14 系统架构
  • 15 敏捷开发(11)
  • 16 案例分析(30)
  • 17 Workflow(1)
  • 18 配置管理(1)
  • 19 项目管理
  • 20 英语(4)

新闻分类(52)

  • CXF学习
  • Hibernate学习(1)
  • iBatis学习(16)
  • Struts1学习(1)
  • Struts2学习(34)

.NET资源

  • adxmenu
  • C# Open Source
  • DNN Directory
  • M2Land
  • Windows Form FAQ
  • 中国DNN
  • 中国DNN联盟

Ajax

  • DoJo
  • GWT
  • JQuery
  • jquery autocomplete
  • jquery flexgrid
  • JQuery Form
  • jquery masked input
  • JQuery UI
  • jquery validation
  • Jquery 图表
  • jquery报表
  • jquery插件集合
  • Qooxdoo
  • Tibco GI
  • YUI
  • YUI-EXT
  • ZeroKode

Java开源

  • ABLE
  • Agile Tao
  • Ajax4JSF
  • Alfresco
  • AppFuse
  • Compiere
  • Equinox
  • Findbugs
  • Geronimo
  • Grails
  • Harmony
  • Hibernate论坛
  • JAG
  • Java开源大全
  • Java视线论坛
  • jBPM工作流
  • JSFTutorials
  • Nereide ERP
  • Ofbiz ERP
  • Opentaps ERP
  • operamasks
  • Petstore
  • Prototype.js
  • RIFE
  • Runa
  • SpringSide
  • Struts Menu
  • Sun Glassfish
  • Trails
  • YUI4JSF
  • 满江红

Mobile

  • Sencha

WEB资源

  • DHTML中心
  • DHTML参考手册
  • DHTML文档
  • EclipsePlugin
  • Firebug
  • GRO Clinux
  • jMaki
  • JSTL文档
  • LoadIcon
  • Openlaszlo
  • Struts Menu 展示
  • Web Test Tools
  • WebCtrs
  • Webdeveloper
  • 中国RIA开发者论坛

Workflow

  • E-Workflow
  • JBPM
  • OpenWFE
  • OSWorkflow
  • WFMC
  • Workflow Research

其他连接

  • confach
  • CPP
  • ejay
  • Giovanni
  • 丹佛
  • 交大e-learning
  • 交大研究生院
  • 可恶的猫
  • 天天@blog
  • 我的相册
  • 阿飞

大牛人

  • 32篇JBPM
  • David.Turing
  • HongSoft@业务集成
  • Joel
  • Koen Aers
  • Martinfowler
  • Raible Matt
  • Raible Wiki
  • Scott W.Ambler
  • Tom Baeyens
  • Uncle Bob
  • 一个世界在等待
  • 子在川上曰
  • 小布老师
  • 小明
  • 差沙
  • 徐昊
  • 江南白衣
  • 汪博士
  • 汪小金
  • 银狐999

开源软件

  • 2Bizbox ERP
  • CompiereCRM&ERP
  • EGW
  • Vtiger CRM
  • webERP

敏捷

  • Canoo
  • Cruisecontrol
  • DBUnit
  • EL4Ant
  • Extreme Programming
  • Fit
  • Fitnesse
  • JFrog
  • Liquibase
  • Maven
  • MockObjects
  • Selenium
  • Squish
  • xpairtise
  • XPlanner
  • XProgramming
  • 敏捷联盟

数据库

  • Oracle 中国
  • Oracle-ERP
  • Oracle在线社区

未归类

  • Aquarius Orm Studio
  • mambo建站系统
  • Oracle产品下载
  • 远程同步管理工具Capivara

经典框架

  • Apache Shale
  • formdef-struts
  • FreeMarker 主页
  • JBoss Seam
  • JSF 中心
  • JSF 入门应用
  • JSF中国
  • MyFaces官方
  • Spring 社区
  • Spring专业网站
  • Spring中文论坛
  • Spring参考手册
  • Spring官方网站
  • strecks-struts
  • Struts1
  • Struts2
  • Struts-layout
  • StrutsWiKi
  • Tapestry WIKI
  • Tapestry 官方
  • Tapestry4开发指南
  • Tapestry中文文档
  • Webwork2文档
  • Wicket

网络教程

  • Laliluna
  • RoseIndia
  • Sang Shin
  • Visualbuilder

著名站点

  • Buildix
  • Dev2Dev
  • IBM dev中国
  • InfoQ
  • ITPub
  • Java Eye
  • Java Research
  • JavaRead
  • JavaWorldTW
  • Matrix
  • PHP100
  • PHPX
  • SpringSideWiKi
  • TheServerSide
  • TWPHP
  • 中国工作流论坛

项目管理

  • 管理人网

最新评论

View Post

Winsock示例学习代码

Part 1 Server Form
Option Explicit

Private m_iCurrent As Integer
Private Const c_iMaxConnect As Integer = 2

Private Sub StartListen()

    
If sckProductServer(0).State = sckClosed Then
        Me.check1.Caption 
= "停止侦听"
        Me.check1.Value 
= 1
        sckProductServer(
0).Listen
        
MsgBox ("{Server}开始侦听")
    
End If
    
End Sub

Private Sub StopListen()

    
If sckProductServer(0).State = sckListening Then
        Me.check1.Caption 
= "开始侦听"
        Me.check1.Value 
= 0
        sckProductServer(
0).Close
        
MsgBox ("{Server}停止侦听")
    
End If
    
End Sub

Private Sub StopAllConnect()
    
Dim i As Integer
    
For i = 1 To sckProductServer.UBound
        Unload sckProductServer(i)
        m_iCurrent 
= m_iCurrent - 1
        
Call StartListen
        
MsgBox ("{Server}关闭Socket[" & i & "]")
    
Next i
End Sub

Private Sub Check1_Click()
    
If Me.check1.Value = 1 Then
        
Call StartListen
    
Else
        
Call StopListen
    
End If
End Sub

Private Sub Command1_Click()

    
Call StopAllConnect
    
End Sub

Private Sub Command2_Click()

    
Dim frmNewClient As New frmClient
    frmNewClient.Show
    
End Sub

Private Sub Form_Load()

    m_iCurrent 
= 0
    sckProductServer(
0).Protocol = sckTCPProtocol
    sckProductServer(
0).LocalPort = 7777
    
End Sub

Private Sub sckProductServer_Close(Index As Integer)
    sckProductServer(Index).Close
    Unload sckProductServer(Index)
    m_iCurrent 
= m_iCurrent - 1
    
Call StartListen
End Sub

Private Sub sckProductServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    
    
Dim i As Integer
    
    
For i = 1 To m_iCurrent
        
If Me.sckProductServer(i).State = 0 Then Exit For
    
Next i
    
    
If i > m_iCurrent Then
        
If i <= c_iMaxConnect Then
            m_iCurrent 
= m_iCurrent + 1
            
            Load Me.sckProductServer(m_iCurrent)
            Me.sckProductServer(m_iCurrent).Accept (requestID)
            
MsgBox ("{Server}Socket[" & m_iCurrent & "] 开始连接")
            
If (i = c_iMaxConnect) Then
                Me.sckProductServer(
0).Close
                
Call StopListen
            
End If
        
Else
            Me.sckProductServer(
0).Close
            
Call StopListen
        
End If
    
Else
        Me.sckProductServer(i).Accept (requestID)
        
MsgBox ("{Server}Socket[" & i & "] 开始连接")
    
End If
    
End Sub

Private Sub sckProductServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    
Dim strData As String
    
    Me.sckProductServer(Index).GetData strData
    
MsgBox ("{Server}Socket[" & Index & "]接收数据" & strData)
    
    sckProductServer(Index).SendData (
"OK")
    
MsgBox ("{Server}Socket[" & Index & "]回送OK")
End Sub

Private Sub sckProductServer_Error(Index As Integer, 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 Index > 0 Then
        
'sckProductServer(Index).Close
        Unload sckProductServer(Index)
        m_iCurrent 
= m_iCurrent - 1
        
Call StartListen
    
End If
End Sub
serverSock.gif
Part 2 Client Form
Option Explicit

Private m_bConnected As Boolean

Private Sub Command1_Click()
On Error GoTo ErrorHandle
    
If m_bConnected = True Then
        Me.sckClient.SendData Me.Text1.Text
        
MsgBox ("{Client}发送数据" & Me.Text1.Text)
    
Else
        
MsgBox ("{Client}连接已断开")
    
End If
    
Exit Sub
ErrorHandle:
MsgBox ("连接已断开")
End Sub

Private Sub Form_Load()
'On Error Resume Next
    If Me.sckClient.State <> 0 Then Me.sckClient.Close
    Me.sckClient.Protocol 
= sckTCPProtocol
    Me.sckClient.RemoteHost 
= "localhost"   '网站服务器IP地址
    Me.sckClient.RemotePort = 7777          '网站服务器监听端口
    Me.sckClient.Connect
End Sub

Private Sub Form_Unload(Cancel As Integer)
   
If Me.sckClient.State <> 0 Then Me.sckClient.Close
End Sub

'函数中调用socket.close,否则事件一直发生
Private Sub sckClient_Close()
   
MsgBox ("{Client}关闭Socket")
   m_bConnected 
= False
   Me.sckClient.Close
End Sub

Private Sub sckClient_Connect()
   
MsgBox ("{Client}建立连接成功")
   m_bConnected 
= True
End Sub

Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
    
Dim strData As String
    
    Me.sckClient.GetData strData
    
   
MsgBox ("{Client}接到数据:" & strData)
End Sub

Private Sub sckClient_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 Me.sckClient.State <> 0 Then Me.sckClient.Close
End Sub
ClientSock.gif

posted on 2005-12-06 13:47 MingIsMe 阅读(204) 评论(0)  编辑  收藏 所属分类: 05 微软编程

 
Powered by:
BlogJava
Copyright © MingIsMe