0

I have a form called frmmsg. I get the following warning when I open a new frmmsg :

Only one usage of each socket address (protocol/network address/port) is normally permitted.

How can I open the form using more socket?

This is the code that I'm using:

Imports System.IO
Imports System.Threading
Imports System.Net.Sockets
Public Class frmmsg
    Dim listener As New TcpListener(8000)
    Dim client As TcpClient
    Dim message As String

    Private Sub frmmsg_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim thread As New Thread(New ThreadStart(AddressOf Listening))
        listener.Start()
    End Sub

    Private Sub listening()
        listener.Start()
    End Sub

    Private Sub btnnewform_Click(sender As Object, e As EventArgs) Handles btnnewform.Click
        Dim fnew As New frmmsg
        fnew.Show()
    End Sub
End Class

Where is the problem and how can I solve it?

Eminem
  • 870
  • 5
  • 20
Riski Febriansyah
  • 335
  • 1
  • 8
  • 21

1 Answers1

0

As apparent from the message you can only open one listening socket per port (in general).

Therefore, you must ensure that there is only one instance of TcpListener(8000) at the same time. If you want to have multiple forms open at the same time you need to reference this object not from the form instances. Maybe use a static/shared variable.

usr
  • 168,620
  • 35
  • 240
  • 369