Form not passing IP address

0

I have three forms: 1. Enters in the port number (form 2) 2. Enters in the IP address (form 3) 3. Launches the client socket (form 1)

The port number is being successfully passed and I am able to move the form 2. However, form 2 on the click of the "ok" button gives an error:

System.Net.Sockets.SocketException (0x80004005): The requested address is not valid in its context 127.0.0.0:0 at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)

Port Form OK Button Handler (Form 2)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim OBJ As New Form3
    OBJ.Port = txtSend.Text
    OBJ.Show()
    Me.Hide()
End Sub

IP Address Form OK Button Handler (Form 3)

Public Property Port As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim OBJ As New Form1
    OBJ.IP = txtSend.Text
    OBJ.Show()
    Me.Hide()
End Sub

The function where the IP address and port number should be passed (Form 1)

Public Property Port As String
Public Property IP As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    mobjClient = New TcpClient(IP, CInt(Port))
    DisplayText("Connected to host" & vbCrLf)

    mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoRead, Nothing)

    Send("New client online")
End Sub
vb.net
tcpclient
asked on Stack Overflow Dec 2, 2019 by Anta • edited Dec 2, 2019 by MatSnow

1 Answer

1

Just add the line where the arrow is.

IP Address Form OK Button Handler (Form 3)

Public Property Port As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim OBJ As New Form1
    OBJ.IP = txtSend.Text
    OBJ.Port = Port '<<=====
    OBJ.Show()
    Me.Hide()
End Sub
answered on Stack Overflow Dec 2, 2019 by Mary

User contributions licensed under CC BY-SA 3.0