Dim filebuffer As Byte()
Dim fileStream As Stream
fileStream = File.OpenRead(<file source>)
' 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(<servers name or IPAddress>, <socket>)
Dim networkStream As NetworkStream
networkStream = clientSocket.GetStream()
networkStream.Write(filebuffer, 0, fileStream.Length)
hederimiller said:client:
VB.NET:Dim filebuffer As Byte() Dim fileStream As Stream fileStream = File.OpenRead(<file source>) ' 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(<servers name or IPAddress>, <socket>) Dim networkStream As NetworkStream networkStream = clientSocket.GetStream() networkStream.Write(filebuffer, 0, fileStream.Length)
sorry i cant seem to get my server to work, but maybe this will give you an idea
Private Sub SendFile()
With OpenFileDialog1
.CheckFileExists = True
.Title = ""
.ShowDialog()
End With
Dim IP As String = InputBox("Enter the IP address or hostname of you traget!", _
"IP Address", "127.0.0.1")
Client = New TcpClient
Client.Connect(IP, 1234)
Dim NWStream As NetworkStream = Client.GetStream
Dim bytesToSend(Client.SendBufferSize) As Byte
Dim FI As New FileInfo(OpenFileDialog1.FileName)
ProgressBar1.Maximum = FI.Length
Dim FileSTR As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim FileReader As New BinaryReader(FileSTR)
Dim numBytesRead As Integer
Dim Ipos As Integer
Do Until Ipos >= FI.Length
numBytesRead = FileSTR.Read(bytesToSend, 0, bytesToSend.Length)
NWStream.Write(bytesToSend, 0, numBytesRead)
Ipos = Ipos + numBytesRead
ProgressBar1.Value += numBytesRead
ProgressBar1.Update()
NWStream.Flush()
Loop
Threading.Thread.Sleep(1000)
ProgressBar1.Value = 0
NWStream.Flush()
FileSTR.Close()
FileReader.Close()
Private Sub ReceiveFile()
Try
Dim Client As TcpClient = TCP.AcceptTcpClient()
Dim NWStream As NetworkStream = client.GetStream
Dim bytesToRead(client.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer
Dim BUFFER_SIZE As Integer = client.ReceiveBufferSize
Dim FileSTR As New FileStream(TextBox1.Text, FileMode.Append, FileAccess.Write)
Do
numBytesRead = 0
numBytesRead = NWStream.Read(bytesToRead, 0, BUFFER_SIZE)
FileSTR.Write(bytesToRead, 0, numBytesRead)
Bytes = Bytes + numBytesRead
StatusBarPanel1.Text = "Downloaded: " & Bytes & " KB."
Loop Until numBytesRead = 0
FileSTR.Close()
NWStream.Close()
Client.Close()
MsgBox("All done!")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
REcThread = New Threading.Thread(AddressOf RF)
REcThread.Start()
End Sub
[COLOR=blue][FONT=Courier New]Dim[/FONT][/COLOR][FONT=Courier New] SendBytes [COLOR=blue]As[/COLOR] [COLOR=blue]Byte[/COLOR]() = [COLOR=blue]New[/COLOR] [COLOR=blue]Byte[/COLOR]() {}[/FONT]
[FONT=Courier New]SendBytes = Encoding.ASCII.GetBytes(TextBox1.Text)[/FONT]
[FONT=Courier New]UDPClient.Send(SendBytes, SendBytes.Length)[/FONT]