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 6154137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:12:48+00:00 2026-05-23T20:12:48+00:00

I have a client and a server that I’m trying to get to speak

  • 0

I have a client and a server that I’m trying to get to speak to eachother over my local network (127.0.0.1).

First, I start the ‘server’ application:

public override void StartListening(int port, IPAddress address) {
            listenClient = new TcpListener(address, port);
            listenClient.Start();
            listenDelimiter = new IPEndPoint(address, port);
            if (listenThread != null) listenThread.Abort();
            listenThread = new Thread(new ParameterizedThreadStart(ListenThread));
            listenThread.IsBackground = true;
            listenThread.Start(port);
        }

        public void ListenThread(object o) {
            while (true) {
                try {
                    Socket incomingConnection = listenClient.AcceptSocket();
                    NetworkStream conStream = new NetworkStream(incomingConnection);
                    NetworkConnection nc = new NetworkConnection((incomingConnection.RemoteEndPoint as IPEndPoint).Port, (incomingConnection.RemoteEndPoint as IPEndPoint).Address);
                    Clients.Add(nc);
                    nc.MonitorTCPStream(conStream, this);
                }
                catch (Exception e) {
                    Console.WriteLine("Server has crashed. Networking error: " + e.Message);
                    Console.WriteLine("Will restart in 60 seconds...");
                    Thread.Sleep(60000);
                    StartListening(WORLDMAP_PORT, IPAddress.Any);
                }
            }
        }

Then the ‘client’:

try {
                    if (worldMapConnection != null) worldMapConnection.Close();
                    worldMapConnection = new TcpClient(address.ToString(), port);
                    worldMapConnection.Connect(WORLDMAP_ADDRESS, WORLDMAP_PORT);
                    if (worldMapThread != null) worldMapThread.Abort();
                    worldMapThread = new Thread(new ParameterizedThreadStart(WorldMapListener));
                    worldMapThread.IsBackground = true;
                    worldMapThread.Start();
                    if (Engine.Renderer.GetTopMenu().GetType() == typeof(MenuContainerConnecting)) Engine.Renderer.CloseMenu();
                }
                catch (System.Net.Sockets.SocketException e) {
                    if (Engine.Renderer.GetTopMenu().GetType() == typeof(MenuContainerConnecting)) Engine.Renderer.CloseMenu();
                    switch (e.SocketErrorCode) {
                        case SocketError.AddressAlreadyInUse: {
                                Engine.Renderer.OpenMenu(new MenuContainerNotice("Connection Error", "You already have a copy of the game connected to the game server.", "Okay"));
                            } break;
                        case SocketError.ConnectionRefused: {
                                Engine.Renderer.OpenMenu(new MenuContainerNotice("Connection Error", "The connection was refused by the game server.", "Okay"));
                            } break;
                        case SocketError.HostUnreachable: {
                                Engine.Renderer.OpenMenu(new MenuContainerNotice("Connection Error", "Could not connect to the game server. Check your internet connection.", "Okay"));
                            } break;
                        default: {
                                Engine.Renderer.OpenMenu(new MenuContainerNotice("Connection Error", "Could not connect to the game server. The server may be down for maintenance.", "Okay"));
                            } break;
                    }
                }
                catch (Exception) {
                    if (Engine.Renderer.GetTopMenu().GetType() == typeof(MenuContainerConnecting)) Engine.Renderer.CloseMenu();
                    Engine.Renderer.OpenMenu(new MenuContainerNotice("Connection Error", "Could not connect to the game server. An unknown error has occoured.", "Okay"));
                }

WORLDMAP_ADDRESS is 127.0.0.1. The port used is the same on both applications (8269).

However, when I run the client, it catches a System.Net.Sockets.SocketException, whose message in the debugger is:

“A connect request was made on an already connected socket 127.0.0.1:8269”

I don’t understand this, because my server is using a TcpListener, and the client a TcpClient. Surely this shouldn’t be an issue?

  • 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-23T20:12:49+00:00Added an answer on May 23, 2026 at 8:12 pm

    These two lines in the client are redundant:

                    worldMapConnection = new TcpClient(address.ToString(), port);
                    worldMapConnection.Connect(WORLDMAP_ADDRESS, WORLDMAP_PORT);
    

    Constructing the TcpClient object with an address and port is sufficient to get it to connect.

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

Sidebar

Related Questions

I have a client server application that sends XML over TCP/IP from client to
we're have a client that needs to get interactive messages from a server, from
I have a client/server question that i am trying to figure out the best
I have a client/server application that communicates with .Net remoting. I need my clients
I have a client-server application that uses .net remoting. The clients are in a
I have a client server based windows forms application that needs an administrator only
i have a server - client application that runs on java 1.3; i want
I have a feeling that there must be client-server synchronization patterns out there. But
I have a .NET client application that needs to communicate with a server using
I have client and server programs which now communicate via TCP. I'm trying out

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.