hello, im working on a file transfer program but a cant figure out how to make the main function work, i have spent hours on Google trying to find a solution... but i cant. Now, as you probably have guessed: the main function is to transfer files over the internet, now i would like to accomplish this with a server and client type program, NOT by uploading and downloading files from an ftp server. it would be grate if the method would not consist of timers constantly checking for updates.

thanks in advanced!

P.S dosnt mater if the user needs to port-forward.

Set a breakpoint on this line and run with debugging. Once you hit this breakpoint, hit F11 to step over it. It should show you more details whats wrong.
How did you declare "server"?

Set a breakpoint on this line and run with debugging. Once you hit this breakpoint, hit F11 to step over it. It should show you more details whats wrong.
How did you declare "server"?

i used this exact same code: http://msdn.microsoft.com/de-de/libr...plistener.aspx

I have already tried to solve it with break points and it dint work, when i told it to skip it the program just went "not responding" and it dint give me any more details like you said it would or like i thought it would.

it is waiting for a connection. try to connect with your client to the server and see if it accept this client.
Also it would be good if you post your code.

it is waiting for a connection. try to connect with your client to the server and see if it accept this client.
Also it would be good if you post your code.

I did try to connect, and it dint do anything.

code:

Public Shared Sub Main()

        Dim server As TcpListener
        server = Nothing
        Try
            ' Set the TcpListener on port 13000.
            Dim port As Int32 = 13000
            Dim localAddr As IPAddress = IPAddress.Parse("192.168.1.67")

            server = New TcpListener(localAddr, port)

            ' Start listening for client requests.
            server.Start()

            ' Buffer for reading data
            Dim bytes(1024) As Byte
            Dim data As String = Nothing

            ' Enter the listening loop.
            While True
                Console.Write("Waiting for a connection... ")

                ' Perform a blocking call to accept requests.
                ' You could also user server.AcceptSocket() here.
                Dim client As TcpClient = server.AcceptTcpClient()
                MsgBox("Connected!")

                data = Nothing

                ' Get a stream object for reading and writing
                Dim stream As NetworkStream = client.GetStream()

                Dim i As Int32

                ' Loop to receive all the data sent by the client.
                i = stream.Read(bytes, 0, bytes.Length)
                While (i <> 0)
                    ' Translate data bytes to a ASCII string.
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
                    Console.WriteLine("Received: {0}", data)

                    ' Process the data sent by the client.
                    data = data.ToUpper()
                    Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data)

                    ' Send back a response.
                    stream.Write(msg, 0, msg.Length)
                    Console.WriteLine("Sent: {0}", data)

                    i = stream.Read(bytes, 0, bytes.Length)

                End While

                ' Shutdown and end connection
                client.Close()
            End While
        Catch e As SocketException
            Console.WriteLine("SocketException: {0}", e)
        Finally
            server.Stop()
        End Try

        Console.WriteLine(ControlChars.Cr + "Hit enter to continue....")
        Console.Read()
    End Sub 'Main
Try
            ' Create a TcpClient.
            ' Note, for this client to work you need to have a TcpServer 
            ' connected to the same address as specified by the server, port
            ' combination.
            Dim port As Int32 = 13000
            Dim client As New TcpClient(server, port)

            ' Translate the passed message into ASCII and store it as a Byte array.
            Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

            ' Get a client stream for reading and writing.
            '  Stream stream = client.GetStream();
            Dim stream As NetworkStream = client.GetStream()

            ' Send the message to the connected TcpServer. 
            stream.Write(data, 0, data.Length)

            Console.WriteLine("Sent: {0}", message)

            ' Receive the TcpServer.response.
            ' Buffer to store the response bytes.
            data = New [Byte](256) {}

            ' String to store the response ASCII representation.
            Dim responseData As [String] = [String].Empty

            ' Read the first batch of the TcpServer response bytes.
            Dim bytes As Int32 = stream.Read(data, 0, data.Length)
            responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
            Console.WriteLine("Received: {0}", responseData)

            ' Close everything.
            stream.Close()
            client.Close()
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: {0}", e)
        Catch e As SocketException
            Console.WriteLine("SocketException: {0}", e)
        End Try

        Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
        Console.Read()
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked = True Then
            FilePortal.Main()
        End If
    End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton1.Checked = True Then
            FilePortal.Connect(TextBox1.Text, "HELLO PC!")
        End If
    End Sub
This article has been dead for over six months. Start a new discussion instead.