这里有个例子:
一·Winsock的主要属性、事件和方法Winsock是不可见控件,控件文件名是MSWINSCK.OCX,全称为Mcirosoft winsock control,使用时要将此控件调入工具箱。1·属性:①Protocol=0 //使用TCP协议;②RemoteHost //准备连接远程机的IP地址③RemotePort //连接远程机的IP端口号 (1024—65535之间)④LocalPort //本地机监听IP端口号必须与呼叫机端口号相同2·方法:①connect //申请连接远程机②listen //设置监听③accept //建立实际连接④senddata //发送数据⑤getdata //接收数据⑥close //关闭连接3·事件:①connectionrequest //一方请求连接时另一方产生②connect //一方机接受连接时另一方产生③close //一方机关闭连接时另一方产生④dataArrival //一方发送数据另一方产生⑤error //请求连接失败时产生二·制作方法⑴ 在一工程中添加两个表单form1(模拟客户端)、form2(模拟服务器端)。form1中装入控件:控件名
主要属性
用途VB.Form form1
caption=”雷萌聊天室”controlbox=0 ‘False
模拟客户机表单VB.Textbox text1
multiline=-1 ‘Truescrollbars=3 ‘Bath
用于输入发往聊天室的信息VB.Textbox text2
locked=-1 ‘Truemultiline=-1 ‘Truescrollbars=3 ‘Bath
显示从聊天室发来的信息VB.Combobox combo1
text=”10.84.234.11” ‘任定默认地址
放入常用的地址VB.Commandbutton comm1
caption=”退出”
最小化form1VB.Commandbutton comm2
caption=”连接”
请求与输入的地址连接VB.Commandbutton send
caption=”发送”
发送Text1中的内容VB.Label label1
caption=“请在此输入发表的信息”
Text1的框标VB.Label label2
caption=“聊天室或对方的信息”
Text2的框标VB.Label label3
caption=”等待连接”
显示连接状态信息VB.Label label4
caption=”聊天室或对方地址”
用于指示Combo1VB.Label label5
caption=”操作:选地址连接,连接成功看到聊天室内容后再输信息发送”
操作说明VB.Timer timer1
interval=6000; enabled=false
防止连接超时MSWinsocklib.winsock a用于数据传输
form2中装入控件:控件名
主要属性
用途VB.Form form2
caption=”接收信息”controlbox=0 ‘False
模拟客户机表单VB.Commandbutton command1
caption=”返回”
隐含Form2窗口VB.Commandbutton command2
caption=”对话”
点对点会话时用此直接启动Form1VB.Textbox text1
locked=-1 ‘Truemultiline=-1 ‘Truescrollbars=3 ‘Bath
存放聊天或对话内容VB.Label label1
caption=”接收的信息”
Text1的框标MSWinsocklib.Winsock a用于监听MSWinsocklib.Winsock b用于传送聊天信息
⑵ 在Form1的各控件事件中加入如下代码:Dim flag As Boolean 注释:连接状态变量Private Sub a_Connect()flag = TrueEnd SubPrivate Sub a_DataArrival(ByVal bytesTotal As Long)Dim i As Stringa.GetData iLabel3.Caption = "连接成功!"Comm2.MousePointer = 0Form1.MousePointer = 0Timer1.Enabled = FalseIf i = Chr(0) ThenText2.Text = "你是今天第一个进入本聊天室的客户。" + Chr(13) + Chr(10)ElseText2.Text = Text2.Text + iEnd IfText2.SelStart = Len(Text2.Text)Send.MousePointer = 0Combo1.Enabled = FalseComm2.Caption = "断开连接"Text1.SetFocusEnd SubPrivate Sub a_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)flag = FalseTimer1.Enabled = FalseComm2.MousePointer = 0Form1.MousePointer = 0MsgBox "网络连接失败!"Label3.Caption = "等待连接"Combo1.Enabled = TrueCombo1.SetFocusa.CloseComm2.Caption = "连接"End SubPrivate Sub Comm1_Click()a.Close 注释:关闭连接Form1.WindowState = 1End SubPrivate Sub Comm2_Click()If Comm2.Caption = "断开连接" Thena.CloseComm2.Caption = "连接"Label3.Caption = "等待连接"Combo1.Enabled = TrueTimer1.Enabled = FalseComm2.MousePointer = 0Form1.MousePointer = 0ElseText2.Text = ""Label3.Caption = "正在连接.."Comm2.MousePointer = 11Form1.MousePointer = 11Timer1.Enabled = Trueflag = Falsea.Protocol = sckTCPProtocola.RemoteHost = Combo1.Texta.RemotePort = 3000a.ConnectEnd IfEnd SubPrivate Sub Form_DblClick()If MsgBox("关闭本聊天室! 确认吗?", 36, "退出系统") = 6 ThenEndElseForm1.WindowState = 1End IfEnd SubPrivate Sub Form_Load()If App.PrevInstance ThenMsgBox "本系统已经加载,请看任务拦!", 48, "提示"EndEnd Ifflag = FalseLoad Form2 ‘读入form2进入监听End SubPrivate Sub Send_Click()Dim S As StringOn Error GoTo ffff ‘防止链路中断Send.MousePointer = 11If Right(Text1.Text, 1) <> Chr(10) ThenS = Text1.Text + Chr(13) + Chr(10)ElseS = Text1.TextEnd IfIf flag Thena.SendData SEnd IfExit Subffff:MsgBox "连接中断!", 48, "提示"a.CloseSend.MousePointer = 0Comm2.Caption = "连接"Label3.Caption = "等待连接"Combo1.Enabled = TrueComm2.MousePointer = 0Form1.MousePointer = 0Exit SubEnd SubPrivate Sub Timer1_Timer()flag = FalseTimer1.Enabled = FalseComm2.MousePointer = 0Form1.MousePointer = 0MsgBox "网络连接失败(超时) !"Label3.Caption = "等待连接"Combo1.Enabled = TrueCombo1.SetFocusa.CloseComm2.Caption = "连接"End Sub⑶ 在Form2的各控件事件中加入如下代码:Const maxn = 200 ‘最大同时连接本机的客户数Dim user(maxn) As BooleanPrivate Sub Command1_Click()Form2.HideEnd SubPrivate Sub Command2_Click()Load Form1Form1.ShowEnd SubPrivate Sub Form_Load()Dim str1 As StringForm2.Caption = "雷萌通信软件"注释:winsock控件 a 作为服务器程序监听a.LocalPort = 3000a.ListenEnd SubPrivate Sub a_ConnectionRequest(ByVal requestID As Long)Dim i As LongFor i = 1 To maxn ‘当一客户请求时给启动一Winsock控件标志号If Not user(i) Thenuser(i) = TrueExit ForEnd IfNext iIf i > maxn ThenExit SubEnd IfLoad b(i) ‘当一客户请求时启动一Winsock控件b(i).Accept requestID 注释:实际建立连接If Text1.Text = "" Then 注释:发送数据b(i).SendData Chr(0)Elseb(i).SendData Text1.TextEnd IfForm2.ShowEnd SubPrivate Sub s_Close(Index As Integer)b(Index).Close 注释:关闭连接Unload b(Index) 注释:卸载 一个WinSock 控件user(Index) = FalseEnd SubPrivate Sub b_DataArrival(Index As Integer, ByVal bytesTotal As Long)Dim str As StringDim i As Longb(Index).GetData strText1.Text = Text1.Text + strFor i = 1 To maxnIf user(i) Thenb(i).SendData strEnd IfNext iEnd Sub三·运行本程序在VB6.0中编译通过,运行后最小化到任务栏上,也可以用API的Shell_Notifyicon 函数做入右下角的指示器栏中常驻内存。你可以在网络中用一个固定的机器地址作为聊天讨论室,其他用户都选该机地址连接进入该室聊天或讨论。各用户也可选各自熟悉的地址进行连接对话,双击form1空白处从内存中撤出系统。
0=Reserved 1=tcpmux 2=compressnet 3=compressnet 4=Unassigned 5=Remote Job Entr 6=Unassigned 7=Echo 8=Unassigned 9=Discard 10=Unassigned 11=Active Users 12=Unassigned 13=Daytime 14=Unassigned 15=Unassigned 16=Unassigned 17=Quote of the Day 18=Message Send Protocol 19=Character Generator 20=FTP (Data) 21=FTP (Control) 22=Unassigned 23=Telnet 24=Private mail-system 25=SMTP 26=Unassigned 27=NSW User System FE 28=Unassigned 29=MSG ICP 30=Unassigned 31=MSG Authentication 32=Unassigned 33=Display Support Protocol 34=Unassigned 35=Private printer server 36=Unassigned 37=Time 38=Route Access Protocol 39=Resource Location Protocol 40=Unassigned 41=Graphics 42=Host Name Server 43=Who Is 44=MPM FLAGS Protocol 45=Message Processing Module (recv) 46=mpm-snd, MPM (default send) 47=ni-ftp 48=Digital Audit Daemon 49=login, Login Host Protocol 50=re-mail-ck, Remote Mail Checking Protocol 51=IMP Logical Address Maintenance 52=xns-time, XNS Time Protocol 53=domain, Domain Name Server 54=xns-ch, XNS Clearinghouse 55=ISI Graphics Language 56=XNS Authentication 57=Private terminal access 58=XNS Mail 59=Private file service 60=Unassigned 61=NI MAIL 62=ACA Services 63=Unassigned 64=Communications Integrator (CI) 65=TACACS-Database Service 66=Oracle SQL*NET 67=Bootstrap Protocol Server 68=Bootstrap Protocol Client 69=Trivial File Transfer 70=Gophergopher 71=Remote Job Service 72=Remote Job Service 73=Remote Job Service 74=Remote Job Service 75=any private dial out service 76=Distributed External Object Store 77=any private RJE service 78=vettcpvettcp 79=Finger server 80=HTTP 81=HOSTS2 Name Server 82=XFER Utility 83=MIT ML Device 84=Common Trace Facility 85=MIT ML Device 86=Micro Focus Cobol 87=Private terminal link 88=Kerberos 89=SU/MIT Telnet Gateway 90=DNSIX Securit Attribute Token Map 91=MIT Dover Spooler 92=Network Printing Protocol 93=Device Control Protocol 94=Tivoli Object Dispatcher 95=SUPDUPsupdup 96=DIXIE Protocol Specification 97=Swift Remote Vitural File Protocol 98=TAC Newstacnews 99=Metagram Relay 100=newacct [unauthorized use] 101=NIC Host Name Server 102=ISO-TSAP 103=Genesis Point-to-Point Trans Net 104=ACR-NEMA Digital Imag. & Comm. 300 105=Mailbox Name Nameserver 106=3COM-TSMUX3com-tsmux 107=Remote Telnet Service 108=SNA Gateway Access Server 109=Post Office Protocol - Version 2 110=Post Office Protocol - Version 3 111=SUN RPC 112=McIDAS Data Transmission Protocol 113=Authentication Service 114=Audio News Multicast 115=Simple File Transfer Protocol 116=ANSA REX Notify 117=UUCP Path Service 118=SQL Servicessqlserv 119=Network News Transfer Protocol 120=CFDPTKTcfdptkt 121=Encore Expedited Remote Pro.Call 122=SMAKYNETsmakynet 123=Network Time Protocol 124=ANSA REX Trader 125=Locus PC-Interface Net Map Ser 126=Unisys Unitary Login 127=Locus PC-Interface Conn Server 128=GSS X License Verification 129=Password Generator Protocol 130=cisco FNATIVE 131=cisco TNATIVE 132=cisco SYSMAINT 133=Statistics Service 134=INGRES-NET Service 135=Location Service 136=PROFILE Naming System 137=NETBIOS Name Service 138=NETBIOS Datagram Service 139=NETBIOS Session Service 140=EMFIS Data Service 141=EMFIS Control Service 142=Britton-Lee IDM 143=Interim Mail Access Protocol v2 144=NewSnews 145=UAAC Protocoluaac 146=ISO-IP0iso-tp0 147=ISO-Ipiso-ip 148=CRONUS-SUPPORT 149=AED 512 Emulation Service 150=SQL-NETsql-net 151=HEMShems 152=Background File Transfer Program 153=SGMPsgmp 154=NETSCnetsc-prod 155=NETSCnetsc-dev 156=SQL Service 157=KNET/VM Command/Message Protocol 158=PCMail Serverpcmail-srv 159=NSS-Routingnss-routing 160=SGMP-TRAPSsgmp-traps 161=SNMP 162=SNMP TRAP 163=CMIP/TCP Manager 164=CMIP/TCP Agent 165=Xeroxxns-courier 166=Sirius Systems 167=NAMPnamp 168=RSVDrsvd 169=Send 170=Network PostScript 170=Network PostScript 171=Network Innovations Multiplex 172=Network Innovations CL/1 173=Xyplexxyplex-mux 174=MAILQ 175=VMNET 176=GENRAD-MUXgenrad-mux 177=X Display Manager Control Protocol 178=NextStep Window Server 179=Border Gateway Protocol 180=Intergraphris 181=Unifyunify 182=Unisys Audit SITP 183=OCBinderocbinder 184=OCServerocserver 185=Remote-KIS 186=KIS Protocolkis 187=Application Communication Interface 188=Plus Five's MUMPS 189=Queued File Transport 189=Queued File Transport 190=Gateway Access Control Protocol 190=Gateway Access Control Protocol 191=Prospero Directory Service 191=Prospero Directory Service 192=OSU Network Monitoring System 193=srmp, Spider Remote Monitoring Protocol 194=irc, Internet Relay Chat Protocl 195=DNSIX Network Level Module Audit 196=DNSIX Session Mgt Module Audit Redir 197=Directory Location Service 198=Directory Location Service Monitor 199=SMUX 200=IBM System Resource Controller 201=at-rtmp AppleTalk Routing Maintenance 202=at-nbp AppleTalk Name Binding 203=at-3 AppleTalk Unused 204=AppleTalk Echo 205=AppleTalk Unused 206=AppleTalk Zone Information 207=AppleTalk Unused 208=AppleTalk Unused 209=Trivial Authenticated Mail Protocol 210=ANSI Z39.50z39.50 211=Texas Instruments 914C/G Terminal 212=ATEXSSTRanet 213=IPX 214=VM PWSCSvmpwscs 215=Insignia Solutions 216=Access Technology License Server 217=dBASE Unix 218=Netix Message Posting Protocol 219=Unisys ARPsuarps 220=Interactive Mail Access Protocol v3 221=Berkeley rlogind with SPX auth 222=Berkeley rshd with SPX auth 223=Certificate Distribution Center 224=Reserved (224-241) 241=Reserved (224-241) 242=Unassigned# 243=Survey Measurement 244=Unassigned# 245=LINKlink 246=Display Systems Protocol 247-255 Reserved 256-343 Unassigned 344=Prospero Data Access Protocol 345=Perf Analysis Workbench 346=Zebra serverzserv 347=Fatmen Serverfatserv 348=Cabletron Management Protocol 349-370 Unassigned 371=Clearcaseclearcase 372=Unix Listservulistserv 373=Legent Corporation 374=Legent Corporation 375=Hasslehassle 376=Amiga Envoy Network Inquiry Proto 377=NEC Corporation 378=NEC Corporation 379=TIA/EIA/IS-99 modem client 380=TIA/EIA/IS-99 modem server 381=hp performance data collector 382=hp performance data managed node 383=hp performance data alarm manager 384=A Remote Network Server System 385=IBM Application 386=ASA Message Router Object Def. 387=Appletalk Update-Based Routing Pro. 388=Unidata LDM Version 4 389=Lightweight Directory Access Protocol 390=UISuis 391=SynOptics SNMP Relay Port 392=SynOptics Port Broker Port 393=Data Interpretation System 394=EMBL Nucleic Data Transfer 395=NETscout Control Protocol 396=Novell Netware over IP 397=Multi Protocol Trans. Net. 398=Kryptolankryptolan 399=Unassigned# 400=Workstation Solutions 401=Uninterruptible Power Supply 402=Genie Protocol 403=decapdecap 404=ncednced 405=ncldncld 406=Interactive Mail Support Protocol 407=Timbuktutimbuktu 408=Prospero Resource Manager Sys. Man. 409=Prospero Resource Manager Node Man. 410=DECLadebug Remote Debug Protocol 411=Remote MT Protocol 412=Trap Convention Port 413=SMSPsmsp 414=InfoSeekinfoseek 415=Bnetbnet 416=Silverplattersilverplatter 417=Onmuxonmux 418=Hyper-Ghyper-g 419=Arielariel1 420=SMPTEsmpte 421=Arielariel2 422=Arielariel3
http://www.dapha.net/VB/list.asp?id=986
http://www.dapha.net/VB/list.asp?id=1397
http://www.dapha.net/VB/list.asp?id=1396
给你发了一个
请你告诉我你的名字好么?我会将你的名字写上去的!!sippey(sippey) 的问题"是什么比赛"
是 "全国中学生计算机应用技术比赛----VB区"