vb2008socket简单数据收发

vb2008socket简单数据收发,第1张

概述Imports Microsoft.VisualBasic Imports System.Net.Sockets Imports System.Net Imports System.Text Public Class Form2     Public s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType

imports Microsoft.VisualBasic
imports System.Net.sockets
imports System.Net
imports System.Text
Public Class Form2
Public s = New Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp)

Private Sub btnsend_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnconnect.Click
Try
Dim result As String = String.Empty '返回结果字符窜
Dim bytes(2048) As Byte '缓存字段
Dim localEndPoint As New IPEndPoint(IPAddress.Parse("119.6.132.49"),23) '设置IP终端
s.Connect(localEndPoint) '链接终端
delay(1000) '延迟1000秒,以便下面接收响应,时延的大小更具时间和返回值确定
s.Receive(bytes) '接收socket数据
result = En@R_403_5563@.ASCII.GetString(bytes) '返回值使用ascii 编解码
txt_result.Text = result '显示返回值
save_result("dsp.txt",result) '保存返回结果
Catch ex As Exception
End Try

End Sub

Private Sub button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btncommand.Click
Dim bytes(2048) As Byte
Dim result As String = String.Empty
s.Send(En@R_403_5563@.ASCII.GetBytes(txtBox_command.Text & Chr(13))) '发送文本框中的命令并加一个回车
delay(1000) '延迟1000秒,以便下面接收响应,时延的大小更具时间和返回值确定
s.Receive(bytes) '接收socket数据
result = En@R_403_5563@.ASCII.GetString(bytes) '返回值使用ascii 编解码
txtBox_command.Text = String.Empty
txt_result.Text = result
save_result("dsp.txt",result) '保存返回结果

End Sub
Sub save_result(ByVal fname As String,ByVal infos As String)
System.IO.file.AppendAllText(fname,infos)
End Sub
Public Sub delay(ByVal msec As Long)
On Error Resume Next
Dim tstart As Single
tstart = Timer
While (Timer - tstart) < (msec / 1000)
Application.DoEvents()
End While
End Sub

Private Sub txtBox_command_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles txtBox_command.TextChanged

End Sub End Class

总结

以上是内存溢出为你收集整理的vb2008socket简单数据收发全部内容,希望文章能够帮你解决vb2008socket简单数据收发所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1267371.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存