回复 18# txm888
给你写个TCP的例子,先运行服务端,再运行发送端
服务端:TCPStartup()
$socket = TCPListen("127.0.0.1", 12345)
If @error <> 0 Then Exit
$file = FileOpen ("2.jpg",18)
$data2 = ""
$i = 0
While 1
$ConnectedSocket = TCPAccept($Socket)
If $ConnectedSocket == -1 Then ContinueLoop
While 1
$data = TCPRecv($ConnectedSocket, 1024, 1)
If @error Then $data = "done"
If $data <> "" Then
If BinaryLen ($data) < 50 Then $data2 = BinaryToString($data, 4)
If $data2 = "done" Then
FileClose ($file)
ShellExecute("2.jpg")
Exit
EndIf
FileWrite($file, $data)
$i+=1
ToolTip("接收到第"&$i&"个包",200,500)
EndIf
WEnd
WEnd
TCPCloseSocket($socket)
TCPshutdown()
发送端:TCPStartup()
$socket = TCPConnect("127.0.0.1", 12345)
If $socket = -1 Then
MsgBox(0, "出错", "连接到服务器出错,请先运行服务端软件")
Exit
EndIf
$file = FileOpen ("1.jpg",16)
$i=0
While 1
$data = FileRead ($file,1024)
If @error == -1 Then
TCPSend($socket,StringToBinary ("done",4))
FileClose ($file)
Exit
EndIf
TCPSend($socket, $data)
$i += 1
ToolTip ($i,100,200)
WEnd
TCPCloseSocket($socket)
TCPshutdown()
|