怎么样用WINSOCK发送图片呀

888atao 2003-04-22 10:47:54
winsock1.senddata picture1.picture

winsock2.getdata aa
aa应该是什么类型的啊
...全文
53 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongying 2003-05-08
  • 打赏
  • 举报
回复
客户端
Dim strFile As String
Dim buffer() As Byte
Dim lBytes As Long

Private Sub CmdBrowse_Click()
CommonDialog1.ShowOpen
strFile = CommonDialog1.FileName
End Sub

Private Sub CmdSend_Click()
CmdSend.Enabled = False
lBytes = 0
ReDim buffer(FileLen(strFile) - 1)
Open strFile For Binary As 1
Get #1, 1, buffer
Close #1
'Load Winsock1
Winsock1.RemoteHost = "server"
Winsock1.RemotePort = 1001
Winsock1.Connect
LblState.Caption = "connecting...."
End Sub

Private Sub Form_Load()

End Sub

Private Sub Winsock1_Close()
LblState.Caption = "connection closed"
End Sub

Private Sub Winsock1_Connect()
LblState.Caption = "connected"
Winsock1.SendData buffer
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)
MsgBox Description, vbOKOnly, "error"
RichTextBox1.Text = HelpFile
End Sub

Private Sub Winsock1_SendComplete()
LblState = "send complete"
'Unload Winsock1
CmdSend.Enabled = True


End Sub

Private Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
lBytes = lBytes + bytesSent
LblState.Caption = lBytes & " out of " & UBound(buffer) & " bytes sent"
End Sub


服务器端
Dim lPos As Long
Dim lDataSend As Long
Dim intDataArrivalTimes As Integer
Public bFinished As Boolean

Private Sub Cmdrun_Click()
If Cmdrun.Caption = "run" Then
Cmdrun.Caption = "stop"
Wstcp.LocalPort = 1001
Wstcp.Listen
lDataSend = 0
Else
Wstcp.Close
Close #1
Cmdrun.Caption = "run"
End If
End Sub

Private Sub Wstcp_Close()
Close #1
End Sub

Private Sub Wstcp_ConnectionRequest(ByVal requestID As Long)
If Wstcp.State <> sckClosed Then Wstcp.Close

Wstcp.Accept requestID
intDataArrivalTimes = 1
If Dir("e:\try\aaa.jpg") <> "" Then Kill "e:\try\aaa.jpg"
Open "e:\try\aaa.jpg" For Binary As 1
lPos = 1
End Sub

Private Sub Wstcp_DataArrival(ByVal bytesTotal As Long)
'ReDim buffer(1 To bytesTotal) As Byte
Dim strFile As String
Dim strFileName As String
Dim intI As Integer
Dim buffer() As Byte


Wstcp.GetData buffer
Put #1, lPos, buffer
lPos = lPos + UBound(buffer) + 1
End If
End Sub

Private Sub Wstcp_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)
MsgBox Description, vbOKOnly, "error"
End Sub
Dickson 2003-05-07
  • 打赏
  • 举报
回复
做成二进制文件,先
fishzone 2003-05-07
  • 打赏
  • 举报
回复
dim aa() as byte
open 一个文件于二进制的方式读数组。
但是记住每次发送数组不要超过8K.
sl3000 2003-05-07
  • 打赏
  • 举报
回复
aa 应该是byte

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧