做个telnet功能的程序,但显示出了问题
用Winsock实现TELNET功能。以下是代码Private Sub Command1_Click()
Winsock1.RemoteHost = 192.168.1.1 '目标连接IP
Winsock1.RemotePort = 23 ‘目标端口
Winsock1.Connect ‘连接
End Sub
Private Sub Command2_Click()
Winsock1.SendData Text3.Text & vbCrLf ’将text3的文本内容发送到服务器端
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData a '接收服务器端返回的数据
MsgBox (bytesTotal & StrConv(arrival, vbUnicode))
Text2.Text = StrConv(a, vbUnicode) & vbCrLf 'unicode转码
MsgBox (bytesTotal & StrConv(arrival, vbUnicode)) ‘问题就出在这里
Text3.Text = "": Text3.SetFocus
End Sub
1.如果使用MsgBox (bytesTotal & StrConv(arrival, vbUnicode))这条语句,那么msgbox提示内容和text2.text显示的交换机登陆信息就是完整的,与cmd下telnet 192.168.1.1相同,如下:
***********************************************************
* All rights reserved (2005-2008) *
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
* Notice: *
* This is a private communication system. *
* Unauthorized access or use may lead to prosecution. *
***********************************************************
Login authentication
Password:
2.如果不加这条语句,text2.text内容就是就分成了分两部分显示,最后显示为
Login authentication
Password:
3.由于我的需求是实现程序自动完成连接目标IP,并且自动操作交换机完成某些固定配置,MsgBox将会弹出窗口并停止运行,并且我有点不理解的是如果使用text2.text=(bytesTotal & StrConv(arrival, vbUnicode))仍然会显示不完整,请教了....
--------------------编程问答-------------------- MsgBox (bytesTotal & StrConv(arrival, vbUnicode))
Text2.Text = StrConv(a, vbUnicode) & vbCrLf 'unicode转码
MsgBox (bytesTotal & StrConv(arrival, vbUnicode)) ‘问题就出在这里
改成:
Text2.Text =Text2.Text+ StrConv(a, vbUnicode) & vbCrLf 'unicode转码
试试
补充:VB , 基础类