CodePudding user response:
Using VS2019, Windows 10 system, same configuration in my classmate communication fast running EXE file, for Windows 7 system, speed and obvious slow down,CodePudding user response:
Start listening code//when click start listening on the server side to create a responsible monitor IP address and port number of the Socket
SocketWatch=new Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp);
//to get IP
IPAddress IP=IPAddress. Any;
//create port
IPEndPoint port=new IPEndPoint (IP, 9000);
//to monitor 1
SocketWatch. Bind (port);
LogMessage (" monitor motherboard success... ");
SocketWatch. Listen (10);
BGW=new BackgroundWorker ();
BGW. DoWork +=Listen;
BGW. WorkerSupportsCancellation=true;
if (! BGW. IsBusy)
BGW. RunWorkerAsync (socketWatch);//the background start listening service
Monitoring thread
SocketTest=socketWatch. The Accept ();
IPEndPoint clientipe=(IPEndPoint) socketTest. RemoteEndPoint;
LogMessage (socketTest. RemoteEndPoint. ToString () + ":" + "connection is successful" + "\ r \ n");
ToolStripStatusLabel1. Text=socketTest. RemoteEndPoint. ToString () + ":" + "and the client connection is successful... ";
Bool reConnected=false;
The foreach (var item in socketSendList)
{
If (item. RemoteEndPoint. ToString (). The Split (" : ") [0]==clientipe. Address. The ToString ())
The reConnected=true;
}
if (! The reConnected)
{
SocketSendList. Add (socketTest);
}
The else
{
for (int i=0; i
If (socketSendList [I]==socketTest)
{
SocketSendList. RemoveAt (I);
SocketSendList. Insert (I, socketTest);//remove the old connection, update the new connection
}
}
}
Thread th=new Thread (Recive);
Th. IsBackground=true;
Th. Start (socketTest);
Receiving
The Socket socketSendTest=(Socket) o;
Try
{
While (true)
{
//after the success of the client connection, the server should receive a message from the client
If (socketSendTest==null)
{
LogError (" please choose to send the client ");
break;
}
Byte [] buffer=new byte [1024 * 2];
Int r=socketSendTest. The Receive (buffer);
If (r==0)
{
break;
}
}
}
Command to send
Byte [] newBuffer=HexStrTobyte (command);
Int sleepTime=int. Parse (txtSleepTime. Text);
While (set)
{
Try
{
CompleteHandle1=false;
The foreach (var item in socketSendList)
{
Item. Send (newBuffer);
Thread.sleep (sleepTime);
}
}
The catch (Exception ex)
{
LogError (ex. Message);
break;
}
}
CodePudding user response:
Don't look at light, see network card, networkA gigabit nics and how a MB card than ah,
A MB fiber exclusive and a 200 public router how ratio
Test to be fair, want to test different operating systems, with the local loopback address 127.0.0.1 test, local loopback but nic directly go at PCI bus, it is relatively fair point,
CodePudding user response:
Lamp, test the communication speed is not looking at how much you receive bytes, you can write their own statisticsIf you don't want to write statistics, can in turn off other application cases, the network part of the Windows performance counters (Windows performance counters in the Windows task manager are hid, oneself look)
CodePudding user response:
Open the performance monitor, monitor the network traffic,https://www.cnblogs.com/deepthought/p/11408176.html