Home > Net >  Vb.net TCP/IP transfer file cannot be opened
Vb.net TCP/IP transfer file cannot be opened

Time:09-15

Dear god, please correct me:
I use VB.net to use TCP/IP in the transmission of file, the client and the server files can be sent in the past, and the same size, but sometimes I can't open, especially the exe file is 100% can't open it, consult the reason?

Client:
Sub file_trancelate_common (logon_IP As String, file_path As String)
Dim file_socket As New Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp)
Dim the endPoint As New IPEndPoint (.net. IPAddress. Parse (logon_IP), 9833) '
Dim the file As FileStream=New FileStream (file_path, FileMode OpenOrCreate, FileAccess. Read)
Dim byteArray containing (file. The Length - 1) As Byte
Dim binaryRead As New BinaryReader (file)
BinaryRead. Read (byteArray containing, 0, the file. The Length - 1)
File_socket. Connect (endPoint)
File_socket. Send (byteArray containing)
File. The Close ()
File_socket. Shutdown (SocketShutdown. Send)
File_socket. Close ()

End Sub

Server:
Sub file_load (IIP As String, pic_name As String, pic_counts As Int16, file_folder As String)

While isisrun
Dim fileStream As fileStream=New fileStream (Application. StartupPath & amp; "" & amp; File_folder & amp; "" & amp; Pic_name, FileMode OpenOrCreate, FileAccess. ReadWrite)
Dim byteArray containing (file_length) As Byte
Dim receiveSocket As.net. Sockets. The Socket=file_socket. Accept ()
Dim binary As New BinaryWriter (fileStream) 'flow write
ReceiveSocket. The Receive (byteArray containing)
Binary. Write (byteArray containing, 0, byteArray containing. Length - 1)
Pic_tran=pic_tran + 1
If byteArray containing. Length - 1=file_length Then
Isisrun=False
FileStream. Close ()
ReceiveSocket. Shutdown (SocketShutdown. The Receive)
ReceiveSocket. Close ()
End the If
End While

End Sub


Outside, don't want to ask next: how to realize the file some of the information and documents enclosed in a block, such as the file size, format and other information to send to the server with the file?
  • Related