发送文件TCP / IP VB.NET [英] Send file TCP/IP VB.NET
本文介绍了发送文件TCP / IP VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我已经在vb.net服务器和client.i中添加函数发送和接收文件并且工作正常,但是当要转移的文件是> 50kb代码无效。为什么?
收到
Dim x As Integer
x = ListView1.FocusedItem.Index
Dim bytesToRead(cliente(x).ReceiveBufferSize) As Byte
' ---读取传入流
Dim numBytesRead As 整数 = flusso(x).Read (bytesToRead,
0 , CInt (cliente(x).ReceiveBufferSize))
' ---将字节写入文件
Const FILE_NAME = C:\ Users\Sinestic\Desktop\11.jpg
Dim fs As System.IO.FileStream
fs = 新 FileStream(FILE_NAME,FileMode.CreateNew,
FileAccess.Write)
fs.Write(bytesToRead, 0 ,numBytesRead )
fs.Close()
发件人
Const FILE_NAME = C:\Users\Sinestic\Desktop\10.jpg
Dim NWStream As NetworkStream = cliente.GetStream
Dim bytesToSend(cliente.ReceiveBufferSize)作为 < span class =code-keyword> Byte
Dim fs As FileStream
fs = 新 FileStream(FILE_NAME,FileMode.Open,
FileAccess.Read)
Dim numBytesRead As Integer = fs.Read(bytesToSend,
0 ,bytesToSend.Length)
' ---发送文本
Dim bf 作为 新 BinaryFormatter
NWStream.Write(bytesToSend, 0 ,numBytesRead)
TextBox5.Text =
我的尝试:
i尝试whit小文件,但我需要trasfer大文件
解决方案
Private Sub btnSend_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理btnSend.Click
Dim filebuffer As Byte()
Dim fileStream As Stream
fileStream = File.OpenRead(tbFilename.Text)
'Alocate memory space对于文件
ReDim filebuffer(fileStream.Length)
fileStream.Read(filebuffer,0,fileStream.Length)
'打开TCP / IP连接并发送数据
Dim clientSocket As New TcpClient(tbServer.Text,8080)
Dim networkStream As NetworkStream
networkStream = clientSocket.GetStream()
networkStream.Write(filebuffer,0,fileStream.Length)
end sub
更多信息,请访问http://technotif.com/creating-simple-tcpip-server-client-transfer-data-using-c-vb-net/#83yQ1VtgVbgBmvYE.99
Hi i have write in vb.net server and client.i add on function for send and receive file and work fine,but when the file to trasfer are > 50kb code not work.Why?
receive
Dim x As Integer
x = ListView1.FocusedItem.Index
Dim bytesToRead(cliente(x).ReceiveBufferSize) As Byte
'---read incoming stream
Dim numBytesRead As Integer = flusso(x).Read(bytesToRead,
0, CInt(cliente(x).ReceiveBufferSize))
'---write the bytes to file
Const FILE_NAME = "C:\Users\Sinestic\Desktop\11.jpg"
Dim fs As System.IO.FileStream
fs = New FileStream(FILE_NAME, FileMode.CreateNew,
FileAccess.Write)
fs.Write(bytesToRead, 0, numBytesRead)
fs.Close()
Sender
Const FILE_NAME = "C:\Users\Sinestic\Desktop\10.jpg"
Dim NWStream As NetworkStream = cliente.GetStream
Dim bytesToSend(cliente.ReceiveBufferSize) As Byte
Dim fs As FileStream
fs = New FileStream(FILE_NAME, FileMode.Open,
FileAccess.Read)
Dim numBytesRead As Integer = fs.Read(bytesToSend,
0, bytesToSend.Length)
'---send the text
Dim bf As New BinaryFormatter
NWStream.Write(bytesToSend, 0, numBytesRead)
TextBox5.Text = ""
What I have tried:
i try whit small file but i need trasfer large file
解决方案
Private Sub btnSend_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSend.Click Dim filebuffer As Byte() Dim fileStream As Stream fileStream = File.OpenRead(tbFilename.Text) ' Alocate memory space for the file ReDim filebuffer(fileStream.Length) fileStream.Read(filebuffer, 0, fileStream.Length) ' Open a TCP/IP Connection and send the data Dim clientSocket As New TcpClient(tbServer.Text, 8080) Dim networkStream As NetworkStream networkStream = clientSocket.GetStream() networkStream.Write(filebuffer, 0, fileStream.Length) end sub Read more at http://technotif.com/creating-simple-tcpip-server-client-transfer-data-using-c-vb-net/#83yQ1VtgVbgBmvYE.99
这篇关于发送文件TCP / IP VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文