public static IFFSocket Connect(string host, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken) { string[] strList = host.Split(":"); if (strList.Length != 3) { return(null); } string ip = strList[1]; string[] ipList = ip.Split("//"); if (ipList.Length == 2) { ip = ipList[1]; } else { ip = ipList[0]; } int port = int.Parse(strList[2]); SocketCtrl ctrl = new SocketCtrl(funcMsg, funcBroken); IFFSocket ffsocket = new FFScoketAsync(ctrl); if (ffsocket.Connect(ip, port)) { return(ffsocket); } return(null); }
public void HandleAccepted(IAsyncResult ar) { if (!bRunning) { return; } try { Socket socket = (Socket)ar.AsyncState; //方法参考:http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.endreceive.aspx if (socket != null) { var client = socket.EndAccept(ar); IFFSocket ffsocket = new FFScoketAsync(m_oSocketCtrl.ForkSelf(), client); ffsocket.AsyncRecv(); FFLog.Info(string.Format("scoket: handleAccepted ip:{0}", ffsocket.GetIP())); } } catch (Exception ex) { FFLog.Error("scoket: handleAccepted Error " + ex.Message); } if (bRunning) { m_oSocket.BeginAccept(new AsyncCallback(HandleAccepted), m_oSocket); } }
public static FFSocket connect(string ip, int port, SocketMsgHandler funcMsg, SocketBrokenHandler funcBroken) { SocketCtrl ctrl = new SocketCtrl(funcMsg, funcBroken); FFSocket ffsocket = new FFScoketAsync(new SocketRecvHandler(ctrl.handleRecv), new SocketBrokenHandler(ctrl.handleBroken)); if (ffsocket.connect(ip, port)) { return(ffsocket); } return(null); }
public void handleAccepted(IAsyncResult ar) { try { var socket = ar.AsyncState as Socket; //方法参考:http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.endreceive.aspx if (socket != null) { var client = socket.EndAccept(ar); FFSocket ffsocket = new FFScoketAsync(m_funcRecv, m_funcBroken, client); ffsocket.asyncRecv(); m_oSocket.BeginAccept(new AsyncCallback(handleAccepted), m_oSocket); } } catch (Exception ex) { WriteLine("scoket: handleAccepted Error " + ex.Message, ConsoleColor.Red); } }
public void HandleAccepted(IAsyncResult ar) { try { Socket socket = (Socket)ar.AsyncState; //方法参考:http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.endreceive.aspx if (socket != null) { var client = socket.EndAccept(ar); IFFSocket ffsocket = new FFScoketAsync(m_funcRecv, m_funcBroken, client); ffsocket.AsyncRecv(); m_oSocket.BeginAccept(new AsyncCallback(HandleAccepted), m_oSocket); } } catch (Exception ex) { FFLog.Trace("scoket: handleAccepted Error " + ex.Message); } }