Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket Low Transfer Speed - Win7 .Net4 - CentOSx64 Mono 2.10
    primarykey
    data
    text
    <p>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.</p> <p>Speed test:</p> <p>Local: 1MB</p> <p>Lan: 1MB</p> <p>Running server on CentOS: 0~10~20 KB</p> <p>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:</p> <p>Server:</p> <pre><code>class Program { private static BackgroundWorker _ListeningWorker; private static BackgroundWorker _QWorker; private static System.Net.Sockets.Socket _Server; private static List&lt;System.Net.Sockets.Socket&gt; ConnectedClients = new List&lt;System.Net.Sockets.Socket&gt;(); 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 &gt; 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 &lt; ConnectedClients.Count; i++) if (ConnectedClients[i].Equals(client)) { ConnectedClients.RemoveAt(i); i--; } } } </code></pre> <p>Client:</p> <pre><code>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 &gt; 0) { byte[] z = new byte[1024]; int r = Client.Receive(z); ; p += r; } else { System.Threading.Thread.Sleep(10); } if (Environment.TickCount - t &gt;= 1000) { t = Environment.TickCount; Console.WriteLine(Program.FormatFileSizeAsString(p) + " Readed,"); p = 0; } } } public static string FormatFileSizeAsString(int len) { if (len &lt; 750 &amp;&amp; len &gt; 0) return "0.0 B ~"; string[] Suffix = { "B", "KB", "MB", "GB", "TB" }; int i; double dblSByte = len; for (i = 0; (int)(len / 1024) &gt; 0; i++, len /= 1024) dblSByte = len / 1024.0; return String.Format("{0:0.0} {1}", dblSByte, Suffix[i]); } } </code></pre> <p>Thanks all, Please tell me what you think about possible problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload