无忧技术网 - RSS订阅 
无忧技术网

用VB的WINSOCK控件发送大于8K的BMP


作者:[佚名] - 发布:2010-4-22 17:35:38 - 来源:无忧技术网
服务器端: 
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const theScreen = 1

Private Sub Form_Load()
tcpServer.LocalPort = 1001 ' 设置监听端口号
tcpServer.Listen ' 开始监听


End Sub

Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
If tcpServer.State <> sckClosed Then tcpServer.Close
tcpServer.Accept requestID

End Sub

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
Dim a As String
tcpServer.GetData a


If a = "b" Then
Call keybd_event(vbKeySnapshot, theScreen, 0, 0)

Picture1.Picture = Clipboard.GetData(vbCFBitmap)
SavePicture Picture1.Image, "d:\ww.bmp"

 

Dim buf() As Byte
Dim position As Long
Open "d:\ww.bmp" For Binary As #1
position = 0
Do While Not EOF(1)
position = positon + 1
ReDim Preserve buf(1 To position)
Get #1, , buf(position)
Loop
Close #1

tcpServer.SendData buf

End If

End Sub

客户端:
Private Sub Command1_Click()


tcpClient.RemoteHost = txtip.Text
tcpClient.RemotePort = 1001
tcpClient.Connect ' 进行连接


End Sub

Private Sub Command2_Click()
Picture1.Picture = LoadPicture("d:\wr.bmp")
End Sub

Private Sub Command3_Click()

tcpClient.SendData "b"
End Sub

Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)


Dim receivefile(1 To 119862) As Byte
tcpClient.GetData receivefile, vbArray + vbByte

'告诉Winsock控件收到的是字节数组类型的数据
Open "d:\wr.bmp" For Binary As #1

Put #1, , receivefile

Close #1

End Sub

Private Sub Winsock1_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)

End Sub

Private Sub Text1_Change()

End Sub

责任编辑:liqwei
打印本页】【关闭本页】【返回列表
·上一篇:利用Winsock控件实现局域网通信
·下一篇:用Winsock编写网络通信程序
 文章评分
  • current rating
-5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5
 相关文章
·[VB/VBs/VB.net]利用Winsock控件实现局域网通信 (2010-04-22)
 相关评论
 站点最新文章 更多>> 
·[经典影音]弱点
·[经典影音]萨利机长
·[经典影音]天空之眼
·[管理知识]康奈尔笔记法,提高100%学习效率
·[管理知识]刘强东:我管75000人靠这4张表格
·[管理知识]跟壳牌学HSE管理
·[运营策划]编辑工作内容整理
·[至理名言]奋斗与决定
·[瀚海拾遗]盲人打灯笼之各家论道
·[搞笑段子]中国男足
 站点浏览最多 更多>> 
·[协议规范]http断点续传原理:http头 Range、…
·[JS/CSS/HTML]HTML 空格的表示符号 nbsp / en…
·[NoSQL]Mongo数据库简介
·[协议规范]什么是SPF记录?如何设置、检测SP…
·[协议规范]图解 HTTPS 通信过程
·[PHP]精选国外免费PHP空间推荐
·[程序综合]常用IP地址查询接口
·[程序综合]什么是 DNS Prefetch ?
·[程序综合]获取客户端IP地址的三个HTTP请求…
·[Linux]/usr 目录的由来