Click here to Skip to main content
15,884,783 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,i have created a program for chatting which works when i select 192.16.1.2 as my ip.

Whenever i try to put my real ip i get the following error:
System.Net.Sockets.SocketException: 'The requested address is not valid in its context'



my code is :

Sub Main()
        Dim localAdd As System.Net.IPAddress = System.Net.IPAddress.Parse("192.168.1.2")
        Dim listener As New System.Net.Sockets.TcpListener(localAdd, portNo)
        listener.Start()

        While True
            Dim user As New ChatClient(listener.AcceptTcpClient)
        End While
    End Sub

So i am guessing since on my local network it worls fine,i must be making a mistake in my commands when i try to send my real ip.?
Thank in advance.

What I have tried:

<pre>Sub Main()
        Dim localAdd As System.Net.IPAddress = System.Net.IPAddress.Parse("192.168.1.2")
        Dim listener As New System.Net.Sockets.TcpListener(localAdd, portNo)
        listener.Start()

        While True
            Dim user As New ChatClient(listener.AcceptTcpClient)
        End While
    End Sub
Posted
Updated 28-May-20 3:17am
Comments
phil.o 26-May-20 21:19pm    
What do you mean by your real IP?
abc_ 28-May-20 5:08am    
i meant this: i have the server which runs on 1 computer and the client which run o different computer with diferent ip,not in the same network in ohter words. so when i put on server ip the ip assign to the computer hosting the server in oorder for the other computers to connect ot this ip,i get that message.

See How to Allow Desktop Applications Through the Windows Firewall here:
Network Security: Windows Firewall: Your System’s Best Defense[^]
As Windows 10 Control Panel naming changes now and then it might be easiest to use the Windows Search and type "Firewall" and select "Allow an app through Windows Firewall".

You could also try IPAddress.Any and use a port as in this example: c# - The requested address is not valid in its context when i try to listen a port - Stack Overflow[^]
 
Share this answer
 
v2
Solution:

Dim listener As New System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, portNo)


I also had to choose as port intead of 500 the port 5000 and do portfowarding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900