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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:35:59+00:00 2026-06-17T22:35:59+00:00

I have created a simple client/server app and it works great (1MB/s which is

  • 0

I have created a simple client/server app and it works great (1MB/s which is max speed i set for server to send) when i run in locally or under Lan network. But when i try to run it in one of my Dedicate Server/VPS my download speed become slow.
I am using CentOS on servers and Mono for running it, Mono version is 2.10.2 and CentOs is 64bit version. Created using framework 4.

Speed test:

Local: 1MB

Lan: 1MB

Running server on CentOS: 0~10~20 KB

My connection speed is 2Mb or ~250KB. It will give me full speed some times. But very rare and i cant see why it give my full speed sometimes and sometimes no speed at all or why sometimes only 10KB and other times only 20KB. Also, i am running client part on my Win7 Desktop. Here is code for server and client part:

Server:

class Program
{
    private static BackgroundWorker _ListeningWorker;
    private static BackgroundWorker _QWorker;
    private static System.Net.Sockets.Socket _Server;
    private static List<System.Net.Sockets.Socket> ConnectedClients = new List<System.Net.Sockets.Socket>();
    static void Main(string[] args)
    {
        Program._ListeningWorker = new BackgroundWorker();
        Program._ListeningWorker.WorkerSupportsCancellation = true;
        Program._ListeningWorker.DoWork += _ListeningWorker_DoWork;
        Program._QWorker = new BackgroundWorker();
        Program._QWorker.WorkerSupportsCancellation = true;
        Program._QWorker.DoWork += _QWorker_DoWork;
        Program.Start();
        while (true)
        {
            Console.Clear();
            Console.WriteLine("1.0.0.1");
            Console.WriteLine(Program.ConnectedClients.Count.ToString());
            System.Threading.Thread.Sleep(1000);
        }
    }
    public static bool Start()
    {
        if (!Program._ListeningWorker.IsBusy)
        {
            Program._Server = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 8081);
            Program._Server.Bind(ipLocal);
            Program._Server.Listen(10);

            Program._ListeningWorker.RunWorkerAsync();
            Program._QWorker.RunWorkerAsync();
        }

        return true;
    }
    private static void _ListeningWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        while (!Program._ListeningWorker.CancellationPending)
        {
            if (Program._Server.Poll(10, SelectMode.SelectRead))
            {
                lock (ConnectedClients)
                {
                    Program.ConnectedClients.Add(Program._Server.Accept());
                }
            }
            System.Threading.Thread.Sleep(1);
        }
        Program._Server.Close();
    }
    private static void _QWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        byte[] array = new byte[1024];
        Random random = new Random();
        while (!Program._QWorker.CancellationPending)
        {
            if (ConnectedClients.Count > 0)
            {
                System.Net.Sockets.Socket[] st;
                lock (ConnectedClients)
                {
                    st = new System.Net.Sockets.Socket[Program.ConnectedClients.Count];
                    ConnectedClients.CopyTo(st);
                }

                foreach (System.Net.Sockets.Socket ser in st)
                {

                    random.NextBytes(array);
                    try
                    {
                        ser.BeginSend(array, 0, array.Length, SocketFlags.None, (AsyncCallback)delegate(IAsyncResult ar)
                        {
                            try
                            {
                                ser.EndSend(ar);
                            }
                            catch (Exception)
                            {
                                iDissconnected(ser);
                            }
                        }, null);
                    }
                    catch (Exception)
                    {
                        iDissconnected(ser);
                    }
                }
            }
            System.Threading.Thread.Sleep(1);
        }
        Program._Server.Close();
    }
    internal static void iDissconnected(System.Net.Sockets.Socket client)
    {
        lock (ConnectedClients)
            for (int i = 0; i < ConnectedClients.Count; i++)
                if (ConnectedClients[i].Equals(client))
                {
                    ConnectedClients.RemoveAt(i);
                    i--;
                }
    }
}

Client:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Enter IP Address: ");
        string Address = Console.ReadLine();
        Console.WriteLine();
        ushort Port = 8081;
        System.Net.Sockets.Socket Client;
        Client = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        Client.Connect(Address, (int)Port);
        Console.WriteLine("Connected");
        int p = 0;
        int t = Environment.TickCount;
        while (true)
        {
            if (Client.Available > 0)
            {
                byte[] z = new byte[1024];
                int r = Client.Receive(z); ;
                p += r;
            }
            else
            {
                System.Threading.Thread.Sleep(10);
            }
            if (Environment.TickCount - t >= 1000)
            {
                t = Environment.TickCount;
                Console.WriteLine(Program.FormatFileSizeAsString(p) + " Readed,");
                p = 0;
            }
        }
    }
    public static string FormatFileSizeAsString(int len)
    {
        if (len < 750 && len > 0)
            return "0.0 B ~";
        string[] Suffix = { "B", "KB", "MB", "GB", "TB" };
        int i;
        double dblSByte = len;
        for (i = 0; (int)(len / 1024) > 0; i++, len /= 1024)
            dblSByte = len / 1024.0;
        return String.Format("{0:0.0} {1}", dblSByte, Suffix[i]);
    }
}

Thanks all, Please tell me what you think about possible problems.

  • 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-06-17T22:36:00+00:00Added an answer on June 17, 2026 at 10:36 pm

    It was some sort of limitation by ISP per each connection.
    Solving was funny. I used to send a HTTP Header before my request and ISP increased my speed because of that.

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

Sidebar

Related Questions

I have created my web socket server and client using this simple tutorial here
I'm writing a simple console client-server app using MSMQ. I'm attempting to run it
I have created very simple app with persistence context (hibernate as provider) to read
i have created a simple public ref class in the vc++ project, which is
I have created a simple JSF image browsing app, and I'm having a problem
I have created a simple web application which runs locally and makes use of
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I am new to Repository concept and get some questions. I have created simple
I have created the simple web service. Code: [ServiceContract] public interface ITsdxService { [OperationContract]

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.