《VB局域网简单聊天器》由会员分享,可在线阅读,更多相关《VB局域网简单聊天器(3页珍藏版)》请在金锄头文库上搜索。
1、AablS2Jarrliii-B:誉SL.HPrivateSubcmd_connect_Click()取得远端机IP,并请求连接SockClient.RemoteHost=txt_ip.TextSockClient.ConnectEndSubPrivateSubcmd_quit_Click()EndEndSubPrivateSubcmd_send_Click()发送文本DimMySendDataAsStringMySendData=txt_send.TextSockClient.SendDataMySendDatatxt_send.Text=”EndSubPrivateSubcmd_end_C
2、lick()发送退出请求,由服务器关闭SockClient.SendDataquitEndSubPrivateSubForm_Load()服务器开始监听SockServer.ListenEndSubPrivateSubSockClient_Close()激活连接按钮cmd_connect.Enabled=Truetxt_send.Text=txt_get.Text=EndSubPrivateSubSockClient_Connect()MsgBox连接成功,vbInformation,ok!使连接按钮无效,避免错误cmd_connect.Enabled=FalseEndSubPrivateSu
3、bSockClient_Error(ByValNumberAsInteger,DescriptionAsString,ByValScodeAsLong,ByValSourceAsString,ByValHelpFileAsString,ByValHelpContextAsLong,CancelDisplayAsBoolean)出错后关闭SockClient.CloseEndSubPrivateSubSockServer_Close()cmd_connect.Enabled=TrueEndSubPrivateSubSockServer_ConnectionRequest(ByValrequest
4、IDAsLong)判断服务器不关闭时接受连接请求IfSockServer.StatesckClosedThenSockServer.CloseSockServer.AcceptrequestIDEndSubPrivateSubSockServer_DataArrival(ByValbytesTotalAsLong)DimMyGetDataAsString得到数据SockServer.GetDataMyGetDataIfMyGetData=quitThenSockServer.CloseSockServer.ListenEndIftxt_get.Text=txt_get.Text&Chr(13)
5、&Chr(10)&MyGetDataEndSubPrivateSubTimer1_Timer()不断的监控服务器和客户端状态SelectCaseSockClient.StateCase0:StatusBar1.Panels(2)=客户端关闭Case1:StatusBar1.Panels(2)=客户端打开Case7:StatusBar1.Panels(2)=客户端已经连接EndSelectSelectCaseSockServer.StateCase0:StatusBar1.Panels(1)=服务器关闭Case2:StatusBar1.Panels(1)=服务器侦听Case7:StatusBar1.Panels(1)=服务器已经连接EndSelectEndSubPrivateSubtxt_get_Change()EndSubPrivateSubtxt_send_KeyPress(KeyAsciiAsInteger)发现按下回车键时就发送文本IfKeyAscii=13Thencmd_send_ClickEndIfEndSub