仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1616|回复: 18
打印 上一主题 下一主题

[学习教程] ASP网页设计一个Winsock组件

[复制链接]
活着的死人 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:34:05 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用filesystemobject,可以对服务器上的文件进行操作,浏览、复制、移动、删除等。有ado的支持,asp对数据库的操作非常得心应手。你甚至可以像使用本地数据库那样,管理远程主机上的数据库,对表格、记录进行各种操作。   我本人写了一个Winsock组件,很复杂,将带发送的报文发给指定IP的指定端口,并前往应对报文。手艺粗拙, 请人人指教。附源码以下:

-------------------------------------


VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsWinSockEm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'******************************************************************************
'
' clsWinSockEm.CLS
' 嵌入式WinSocket类
' 输出:办事器IP、办事器Port、待发送报文
' 输入:吸收报文
'
'******************************************************************************

Option Explicit

'******************************************************************************

Const RECV_TIME_OUT = 60        ' 吸收超时
Const SEND_TIME_OUT = 60        ' 发送超时
Const CONN_TIME_OUT = 120       ' 毗连超时
Const RECV_MAX_LEN = 2048       ' 吸收报文最大数

'******************************************************************************

Private WithEvents wskEm As MSWinsockLib.Winsock    ' WinSock Control
Attribute wskEm.VB_VarHelpID = -1
Private mstrServerIP As String                      ' 近程办事器IP
Private mintServerPort As Integer                   ' 近程办事器端口
Private mstrTextToSend As String                    ' 发送报文
Private mstrTextReceived As String                  ' 吸收报文
Private bConnected As Boolean                       ' 毗连标记

'******************************************************************************

' 初始化
Public Sub Init(strServerIP As String, intServerPort As Integer)
    mstrServerIP = strServerIP
    mintServerPort = intServerPort
    mstrTextToSend = ""
    mstrTextReceived = ""
    bConnected = False
End Sub

' 前往报文
Public Function ReturnText(strTextToSend As String) As String
    Dim dtStart As Date
    dtStart = Now

    Set wskEm = New MSWinsockLib.Winsock
   
    ' 获得发送字符串
    mstrTextToSend = strTextToSend
    mstrTextToSend = mstrTextToSend & Chr(0)
   
    ConnectServer
    SendText
   
    ' 吸收报文超时掌握
    Do Until Not (mstrTextReceived = "")
        DoEvents
        If DateDiff("s", dtStart, Now) > RECV_TIME_OUT Then
            Err.Raise vbObjectError, "Socket毛病", "通信超时"
        End If
    Loop
   
    wskEm.Close
    Set wskEm = Nothing

    ReturnText = mstrTextReceived
End Function

' 毗连办事器
Private Sub ConnectServer()
    Dim dtStart As Date
   
    dtStart = Now()
   
    wskEm.RemoteHost = mstrServerIP
    wskEm.RemotePort = mintServerPort
    wskEm.Connect
   
    Do Until bConnected
        DoE</p>  因为现在数据库都使用标准的SQL语言对数据库进行管理,所以如果是标准SQL语言,两者基本上都可以通用的。SQL Server还有更多的扩展,可以用存储过程,数据库大小无极限限制。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-6-13 21:14

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表