static void Main(string[] args) { mServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { IPAddress HostIp = IPAddress.Any; IPEndPoint iep = new IPEndPoint(HostIp, 2626); BlinkLog.I("Start Server Socket..."); mServer.Bind(iep); mServer.Listen(Int32.MaxValue); mThread = new Thread(Run); mThread.Start(); } catch (Exception) { BlinkLog.E("Start Server Error."); } BlinkLog.I("=========PRESS ANY KEY TO EXIT=========="); Console.ReadKey(); IsExit = true; if (mThread != null) { mThread.Interrupt(); } mServer.Dispose(); mServer.Close(); }
public void Run() { int err = 0; while (!mQuit) { ReceivePacket packet; try { // Receive head packet = mReceiver.ReceiveHead(); // Adjust Stream packet.AdjustStream(); // Post Start mDelivery.PostReceiveStart(packet); // Receive entity bool status = mReceiver.ReceiveEntity(packet, mDelivery); // Adjust Result value form stream packet.AdjustPacket(); // Post End mDelivery.PostReceiveEnd(packet, status); } catch (Exception e) { if (err > 3) { mBlinkConn.Send("dasds"); } err++; BlinkLog.E(e.ToString()); } finally { sleepSomeTime(); } } }
static void Run() { while (!IsExit) { try { BlinkLog.I("Server Socket Accept..."); Socket socket = mServer.Accept(); BlinkLog.V("New Client Socket."); BlinkConn conn = Utils.bindBlink(socket); conn.GetResource().ClearAll(); mBlinkConn.Add(conn); BlinkLog.V("Socket To BlinkConn OK."); } catch (Exception e) { BlinkLog.E(e.ToString()); } } }
static void Send(string str) { try { FileInfo info = new FileInfo(str); if (info.Exists) { mBlinkConn.Send(info, new SendCallBack()); } else { mBlinkConn.Send(str); BlinkLog.I("Send String To Server."); } } catch (Exception e) { BlinkLog.E(e.Message); } }