Jump to content
  • Advertisement
Sign in to follow this  

Sockets in VB .net

This topic is 4495 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

I tried to create a simple program that sets up a connection using sockets and sends/reads a message. Here is the code, what am I doing wrong? It seems that it is not reading the message.
Imports System.IO
Imports System.Net
Imports System.Net.Sockets

Public Class Form1
    Dim localAddr As IPAddress = IPAddress.Parse("")
    Dim listener As New TcpListener(localAddr, 8080)
    Dim client As New Net.Sockets.TcpClient
    Dim streamText As StreamReader
    Dim strMessage As String
    Dim thrListen As New Threading.Thread(AddressOf Start)

    Dim testConn As New TcpClient()
    Dim outgoing As StreamWriter
    Dim strText As String

    Dim strNetwork As NetworkStream

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Start()
            Console.WriteLine("listener started")
            client = listener.AcceptTcpClient()
            Console.WriteLine("client initiatied")
            streamText = New StreamReader(client.GetStream())
            Console.WriteLine("stream initialized")
            strMessage = streamText.ReadLine
            Console.WriteLine("message read in")

            TextBox1.Text = strMessage
        Catch er As Exception
        End Try
    End Sub

    Private Sub connect()
        strText = "Test"
        testConn.Connect(localAddr, 8080)
        Console.WriteLine("testconn Connected")
        outgoing = New StreamWriter(testConn.GetStream(), System.Text.Encoding.UTF8)
        Console.WriteLine("outgoing initialized")
        Console.WriteLine("Message sent")
    End Sub

End Class

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!