• Advertisement
Sign in to follow this  


This topic is 3814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im having problems for whatever reason trying to get a basic tcp ip client server setup. I dont want it to be ran in console rather in a windows form anyone know of any good links. Here is what im doing. I have a peice of software developed that is goinig to be a auto update software. Only thing im lacking is the network peice. Here is the set up i have now. I have the server code in a module and am trying to use this networkserver.main() in form1.vb now here is my networkserver modual server
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Module networkserver
    Private Stream As NetworkStream

    Public Sub Main()

        ' Create a new listener on port 8000.
        Dim Listener As New TcpListener(8000)

        Console.WriteLine("About to initialize port.")

        Console.WriteLine("Listening for a connection...")

            ' Wait for a connection request, 
            ' and return a TcpClient initialized for communication. 
            Dim Client As TcpClient = Listener.AcceptTcpClient()
            Console.WriteLine("Connection accepted.")

            ' Retrieve the network stream.
            Stream = Client.GetStream()

            ' Create a BinaryWriter for writing to the stream.
            Dim w As New BinaryWriter(Stream)

            ' Create a BinaryReader for reading from the stream.
            Dim r As New BinaryReader(Stream)

            If r.ReadString() = ClientMessages.RequestConnect Then
                Console.WriteLine("Connection completed.")
                Loop Until r.ReadString() = ClientMessages.Disconnect
                Console.WriteLine("Disconnect request received.")
                Console.WriteLine("Could not complete connection.")
            End If

            ' Close the connection socket.
            Console.WriteLine("Connection closed.")

            ' Close the underlying socket (stop listening for new requests).
            Console.WriteLine("Listener stopped.")

        Catch Err As Exception
        End Try

    End Sub
    Public Class ServerMessages

        Public Const AcknowledgeOK As String = "OK"
        Public Const AcknowledgeCancel As String = "Cancel"
        Public Const Disconnect As String = "Bye"

    End Class

    Public Class ClientMessages

        Public Const RequestConnect As String = "Hello"
        Public Const Disconnect As String = "Bye"

    End Class
End Module
For some reason when I click my button it goes into the try and then freezes up. Right around the Dim Client As TcpClient = Listener.AcceptTcpClient() Console.WriteLine("Connection accepted.") now ive tried looking at other code and what not and it all works why wouldnt this work? This code has been taken out of a book "Microsoft Visual Basic.net Programmer's CookBook" and when i run there project it works. So dont make sense to me. theres only 1 difference They dont have any windows forms they are just running it as a straight console app. I have forms but have commented all the console.write and still wont work so what do I need to do? Thanks any help would be great!!!! aim - silentcoast yahoo - aumudin@yahoo.com msn - aumudin@hotmail.com

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement