Asynchronous server to get base 64 strings from several clients

Tags:
Visual Basic
I cant figure out how can change this Visual Basic code to get files parallel with async method. It works fine for one client but i need get files from hundreds of clients in same time.I delete some lines to clear code with * sing Here is my code:
Module Module1
Public destinationfolder As String
Dim rcf As New RecievedFile
Public port As String

Sub Main()
    *
    rcf.Threader = New Thread(New System.Threading.ThreadStart(AddressOf rcf.Recieve))
    rcf.Threader.Start() ''starts listening on port for incoming data
End Sub

Private Sub DrawGraphics(ByVal int As Integer)
    If int = 0 Then
        *
    ElseIf int = 1 Then
        *
    ElseIf int = 2 Then
        *
    End If
End Sub
End Module
And it is my recieve part:
Public Class RecievedFile
Public Threader As Thread
Dim TCPListener As TcpListener
Dim Socket As Socket

Sub Recieve()
    Try
        TCPListener = New TcpListener(IPAddress.Any, port)
        TCPListener.Start()
        While True
            Try
                Socket = TCPListener.AcceptSocketAsync

                Dim MyNetworkStream As NetworkStream = New NetworkStream(Socket)

                Dim mystreamreader As StreamReader = New StreamReader(MyNetworkStream)

                Console.WriteLine("Recieving file...")
                Dim str As String = mystreamreader.ReadToEnd
                Console.WriteLine(str)
                Dim fn As String = str.Remove(str.IndexOf("#"))
                Dim filenamelength As Integer = fn.Length
                Dim b64string As String = str.Substring(str.IndexOf("#") + 1)

                Dim binaryData() As Byte = Convert.FromBase64String(b64string)
                Console.WriteLine("done")


                    Dim fs As New FileStream(destinationfolder & "" & fn, FileMode.CreateNew)
                    fs.Write(binaryData, 0, binaryData.Length)
                    fs.Close()
                    Console.WriteLine("Recieved file: " & fn)


            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End While
    Catch ex2 As Exception
        MsgBox(ex2.Message)
    End Try
End Sub
End Class
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: