急!!!!请问各位老手,高手怎样用udp来发送文件
为什么服务器不能接收到文件,我使用二进制的方法
代码如下:
Private Sub Form_Load()
ws.RemoteHost = "192.168.0.14"
ws.RemotePort = 1001
End Sub
Private Sub t_Click()'t为菜单
Call ws_DataArrival(10)
End Sub
'客户端发送文件
Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Open "t.txt" For Output As #1
Print #1, "aa"
Close #1
'文件以二进制文件的方式来打开,将其内容全部读入一个byte类型的数组中
Dim myfile() As Byte
Dim position As Long
Open "t.txt" For Binary As #1
position = 0
Do While Not EOF(1)
position = positon + 1
ReDim Preserve myfile(1 To position)
Get #1, , myfile(position)
'再向远程机传送这个字节数组
ws.SendData myfile
Loop
Close #1
End Sub
'远程机(服务器端)收到这个数组之后,再以二进制文件的方式打开一个新目标文件,将数组内容写入这个新打开的文件
'远程机代码如下:
Private Sub ws_DataArrival(ByVal bytestotal As Long)
Dim receivefile() As Byte
ReDim Preserve receivefile(1 To bytesTotal)
ws.GetData receivefile, vbArray + vbByte
'告诉Winsock控件收到的是字节数组类型的数据
Open "t.txt" For Binary As #1
For i = 0 To bytestotal - 1
Put #1, , receivefile(i)
Next i
Close #1
End Sub