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(); }
static void Main(string[] args) { for (int i = 0; i <= 50000; i++) { BlinkLog.I("=========" + i + "=========="); Thread thread = new Thread(Run); thread.Start(); Thread.Sleep(500); } BlinkLog.I("=========PRESS ANY KEY TO EXIT=========="); Console.ReadKey(); IsExit = true; }
static void SendWhlie() { while (true) { BlinkLog.V("===== Enter some str or drag file to send. ====="); string str = Console.ReadLine(); if (str == "E") { return; } Send(str); } }
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 Main(string[] args) { BlinkLog.I("=========PRESS ENTER IP eg(127.0.0.1)=========="); string ip = Console.ReadLine(); IPAddress hostIp; if (!IPAddress.TryParse(ip, out hostIp)) { Console.ReadKey(); return; } try { mSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); mSocket.Connect(hostIp, 2626); mBlinkConn = Blink.NewConnection(mSocket, 1024 * 1024, "D:/", Guid.NewGuid().ToString(), 0.01f, null, null); } catch (Exception) { BlinkLog.I("LINK TO: " + hostIp + " ERROR."); Console.ReadKey(); return; } BlinkLog.I("=========PRESS ENTER 'E' TO EXIT=========="); SendWhlie(); if (mBlinkConn != null) { mBlinkConn.Dispose(); } if (mSocket != null) { mSocket.Dispose(); mSocket.Close(); } }
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); } }
static void Run() { while (!IsExit) { try { BlinkLog.I("Server Socket Accept..."); Socket socket = mServer.Accept(); BlinkLog.V("New Client Socket."); BlinkCallBack callback = new BlinkCallBack(socket); BlinkConn conn = callback.Conn; conn.GetResource().ClearAll(); BlinkLog.V("Socket To BlinkConn OK."); } catch (Exception) { // } } }