1)Which protocol more usefull for sending file?

2)There is an application  to bottom.Sometimes; sended files in This application,cannot open to server pc
Sometimes can open;sometimes cannot open.
when 0t may?

 Dim fileBuffer As Byte()
        Dim fileStream As Stream
        fileStream = File.OpenRead("c:\2.jpg")
        ReDim fileBuffer(fileStream.Length)
        fileStream.Read(fileBuffer, 0, fileStream.Length)
        Dim clientSocket As New TcpClient("", 10001)
        Dim netWorkStream As NetworkStream
        netWorkStream = clientSocket.GetStream()
        netWorkStream.Write(fileBuffer, 0, fileStream.Length)


Imports System
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private alSockets As ArrayList

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lblStatus As System.Windows.Forms.TextBox
    Friend WithEvents lbxConnections As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lblStatus = New System.Windows.Forms.TextBox
        Me.lbxConnections = New System.Windows.Forms.ListBox
        Me.lblStatus.Location = New System.Drawing.Point(88, 88)
        Me.lblStatus.Name = "lblStatus"
        Me.lblStatus.Size = New System.Drawing.Size(296, 20)
        Me.lblStatus.TabIndex = 0
        Me.lblStatus.Text = ""
        Me.lbxConnections.Location = New System.Drawing.Point(120, 152)
        Me.lbxConnections.Name = "lbxConnections"
        Me.lbxConnections.Size = New System.Drawing.Size(120, 95)
        Me.lbxConnections.TabIndex = 1
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 374)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim IPHost As IPHostEntry
        IPHost = Dns.GetHostByName(Dns.GetHostName())
        lblStatus.Text = "My IP address is " + IPHost.AddressList(0).ToString()
        alSockets = New ArrayList
        Dim thdListener As New Thread(New ThreadStart(AddressOf ListenerThread))
    End Sub
    Public Sub listenerThread()
        Dim tcpListener As New TcpListener(IPAddress.Any, 1024)
        Dim handlerSocket As Socket
        Dim thdstHandler As ThreadStart
        Dim thdHandler As Thread
            handlerSocket = tcpListener.AcceptSocket
            If handlerSocket.Connected Then
                lbxConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString() + " connected.")
                SyncLock (Me)
                End SyncLock
                thdstHandler = New ThreadStart(AddressOf handlerThread)
                thdHandler = New Thread(thdstHandler)
            End If
    End Sub

    Public Sub handlerThread()
        Dim handlerSocket As Socket
        handlerSocket = alSockets(alSockets.Count - 1)
        Dim networkStream As NetworkStream = New NetworkStream(handlerSocket)
        Dim blockSize As Int16 = 1024
        Dim thisRead As Int16
        Dim dataByte(blockSize) As Byte
        SyncLock Me
            Dim fileStream As Stream
            fileStream = File.OpenWrite("C:\upload.txt")
            While (True)
                thisRead = networkStream.Read(dataByte, 0, blockSize)            '// I'm Getting error in this line
                If thisRead = 0 Then
                    Exit While
                End If
                fileStream.Write(dataByte, 0, dataByte.Length)                         '// I'm Getting error in this line
            End While
        End SyncLock
        lbxConnections.Items.Add("File Written")
        handlerSocket = Nothing
    End Sub
End Class
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Using FTP protocol will be a better solution for file uploading


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
remotedesktopAuthor Commented:

0s there ftp application in visual

C# component can be used in VB.NET and vice versa

You can use following tool to convert C# to VB.NET

Forced accept.

EE Admin
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.