Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3240370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:04:39+00:00 2026-05-17T18:04:39+00:00

I have two .net applications communicating with sockets on port 5672 and everthing works

  • 0

I have two .net applications communicating with sockets on port 5672 and everthing works fine.
On server side, i open the connection with this simple code lines:

IPAddress localAddr = Dns.GetHostEntry("localhost").AddressList[0];  
TcpListener socket = new TcpListener(localAddr, 5672);  
socket.Start();  

If i try to launch another server app, it fails, telling me that the port is already in use.
I have also the same pair of applications writted in C++ (not by me).
To my surprise, i can launch both C++ and .net server at the same time.

The worst is that my C++ client can´t communicate with my .net server (“connection refused”
error).

To understand my problem, i listed the used ports with the command:

netstat -a  

And in the result i had:
TCP 0.0.0.0:5672 <— (this is the c++ server)
TCP [::1] :5672 <— (this is the .net server)

According to my C# code, souldn’t localhost address be 0.0.0.0 or 127.0.0.1?
What’s happening on my .net server?
Waht’s the meaning of [::1] ?

Note:
If i change my code to:

IPAddress localAddr = new IPAddress(new byte[]{0,0,0,0});  

everything works normaly and my C++ client communicate with .net server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:04:39+00:00Added an answer on May 17, 2026 at 6:04 pm

    When I run the following code:

            IPAddress localAddr = Dns.GetHostEntry("localhost").AddressList[0];
            IPAddress localAddr2 = Dns.GetHostEntry("localhost").AddressList[1];
    

    I get the IPV6 address you showed in localAddr, and “127.0.0.1” in localAddr2 (and there are no more entries in AddressList). If you want to use IPv4 you must locate and use the correct address by checking the AddressFamily property in each IPAddress in your list of candidates AddressList.

    You cannot by default listen on the same port/address pair from two apps. If you want to do this (not sure why you would, since this makes the server app that incoming connections hit non-deterministic), then you can do so by setting ExclusiveAddrUse to false on your TcpListener – note however that you have to do this while the listener is Stop-ped.

    Since your C++ app uses ‘0.0.0.0’ directly, it behaves differently. It’s using the IPV4 address and so no conflict results with your IPV6 C# TcpListener.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two separate .NET applications, one server and another WinForms. WinForms app has
I have two .NET applications that talk to each other over a named pipe.
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have two workflow foundation (.NET 3.5 SP 1) application which compiles fine. It
We're seeing an odd pattern in our QA Lab. We have two ASP.NET applications,
I have two .net applications that run on the same machine. The first application
I have two different asp.net web applications both referencing the same dll e.g. SharedLibrary.dll
I have two sets of web applications, one set running under Asp.Net 3.5 and
We host our ASP.NET applications on two web servers (Server 2003, IIS 6) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.