A code scanning gun follows the TCP protocol, and the information scanned by the code scanning gun can be obtained by modifying the code scanning gun; (there is a serial port server);
using System; using ; using ; using ; using ; using ; using ; using ; using ; namespace Demo_Net { //This machine is the server //Add to determine whether the network is connected in the afternoon; and make corresponding judgments; class Program { static Socket msock; static void Main(string[] args) { //First determine whether the ping is available: string ips = "10.18.14.111"; string str = NetConnect(ips); (str); (); } //Discribing whether to connect through ping; private static string NetConnect(string ip) { Process p = new Process(); = ""; = false; = true; = true; = true; = false; string pingstr; (); ("ping -n 1 " + ip); ("exit"); string strRst = (); if (("(0% Lost)") != -1) { pingstr = "Connected successfully"; //Define the socket connection required for the native IP and corresponding port; msock = new Socket(, , ); var localIP = new IPEndPoint(("10.18.14.23"), 10001); (localIP); //Define the maximum number of network connections yourself (10); // Create a new thread to process; Thread th = new Thread(delegate() { Rec(); }); = true; (); } else { pingstr = "Connection timeout"; } (); return pingstr; } // Listen to whether there is a link, and handle the new thread static void Rec() { do { Socket s = (); Thread th = new Thread(delegate() { Parse(s); }); = true; (); } while (true); } // Process the information obtained when there is a link static void Parse(Socket s) { do { byte[] b = new byte[1000]; int l = (b); b = (l).ToArray(); string rs = ; for (int i = 0; i < ; i++) { rs = rs + b[i].ToString(); } //decoding ((b, 0, l)); } while (true); } } }