2个回答
展开全部
发送端:
需要picture控件,winsock控件
Option Explicit
Private Sub Form_Load()
Winsock1(0).Protocol = sckTCPProtocol '使用TCP协议
Winsock1(0).LocalPort = 9999 '设置本地端口
Winsock1(0).RemotePort = 0 '设置要连接的远程端口号
Winsock1(0).Listen '设置为侦听模式
End Sub
'接受连接
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim PBag As New PropertyBag '得到图片信息
Dim PictureByt() As Byte '保存图像
Load Winsock1(Winsock1.Count)
Winsock1(Winsock1.Count - 1).Accept requestID '接受新连接
'---------------------------------------------------------------
PBag.WriteProperty "Picture", Picture1.Picture
PictureByt = PBag.Contents '获取容器Byte到PictureByt()数组中
'---------------------------------------------------------------
Winsock1(Winsock1.Count - 1).SendData PictureByt '发送数据
End Sub
接收端
需要两个按钮
Option Explicit
Private Sub Command2_Click()
Dim bytData() As Byte '接收图片
Dim PBag As New PropertyBag '图片信息
ReDim bytData(1 To Winsock1.BytesReceived) '接收图片大小
Winsock1.GetData bytData '读取缓冲区数据
PBag.Contents = bytData
Set Picture1.Picture = PBag.ReadProperty("Picture") '设置图片
Command2.Enabled = False
End Sub
Private Sub Form_Load()
Command1.Caption = "连接"
Command2.Caption = "显示图片"
Winsock1.Close '关闭连接
Winsock1.Protocol = sckTCPProtocol '使用TCP协议
Winsock1.LocalPort = 0 '动态地建立连接
Winsock1.RemotePort = 9999 '设置要连接的远程端口号
Winsock1.Connect "127.0.0.1" '设置要连接的计算机名称或IP地址
'IP改成要连接的IP
Command1.Enabled = False
End Sub
需要picture控件,winsock控件
Option Explicit
Private Sub Form_Load()
Winsock1(0).Protocol = sckTCPProtocol '使用TCP协议
Winsock1(0).LocalPort = 9999 '设置本地端口
Winsock1(0).RemotePort = 0 '设置要连接的远程端口号
Winsock1(0).Listen '设置为侦听模式
End Sub
'接受连接
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim PBag As New PropertyBag '得到图片信息
Dim PictureByt() As Byte '保存图像
Load Winsock1(Winsock1.Count)
Winsock1(Winsock1.Count - 1).Accept requestID '接受新连接
'---------------------------------------------------------------
PBag.WriteProperty "Picture", Picture1.Picture
PictureByt = PBag.Contents '获取容器Byte到PictureByt()数组中
'---------------------------------------------------------------
Winsock1(Winsock1.Count - 1).SendData PictureByt '发送数据
End Sub
接收端
需要两个按钮
Option Explicit
Private Sub Command2_Click()
Dim bytData() As Byte '接收图片
Dim PBag As New PropertyBag '图片信息
ReDim bytData(1 To Winsock1.BytesReceived) '接收图片大小
Winsock1.GetData bytData '读取缓冲区数据
PBag.Contents = bytData
Set Picture1.Picture = PBag.ReadProperty("Picture") '设置图片
Command2.Enabled = False
End Sub
Private Sub Form_Load()
Command1.Caption = "连接"
Command2.Caption = "显示图片"
Winsock1.Close '关闭连接
Winsock1.Protocol = sckTCPProtocol '使用TCP协议
Winsock1.LocalPort = 0 '动态地建立连接
Winsock1.RemotePort = 9999 '设置要连接的远程端口号
Winsock1.Connect "127.0.0.1" '设置要连接的计算机名称或IP地址
'IP改成要连接的IP
Command1.Enabled = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询