private ActiveIO(Socket ssc, NetSession session, String hostName, int port) { (assoc_session = session).InitSession(); //connectDone = new ManualResetEvent(false); //在 Unity 中 BeginConnect 解析域名阻塞,所以起线程 new Thread(()=>ssc.BeginConnect(hostName, port, new AsyncCallback(ConnectCallback), ssc)).Start(); }
public static PassiveIO Open (NetSession assoc_session) { /* Conf conf = Conf.GetInstance (); String section = assoc_session.Identification (); String type = conf.find (section, "type"); if (String.Compare (type, "tcp", true) == 0) { Socket ssc = null; try { IPEndPoint sa = new IPEndPoint (IPAddress.Parse (conf.find (section, "address")), int.Parse (conf.find (section, "port"))); ssc = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ssc.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); ssc.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); int optval; try { optval = int.Parse (conf.find (section, "so_sndbuf")); if (optval != 0) ssc.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendBuffer, optval); } catch (Exception) { } try { optval = int.Parse (conf.find (section, "so_rcvbuf")); if (optval != 0) ssc.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, optval); } catch (Exception) { } try { optval = int.Parse (conf.find (section, "tcp_nodelay")); if (optval != 0) ssc.SetSocketOption (SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); } catch (Exception) { } ssc.Bind (assoc_session.OnCheckAddress (sa)); try { optval = int.Parse (conf.find (section, "listen_backlog")); if (optval == 0) optval = 128; } catch (Exception) { optval = 128; } ssc.Listen (optval); return (PassiveIO)register (new PassiveIO (ssc, assoc_session, Type.STREAM)); } catch (Exception e) { Console.WriteLine (e.StackTrace); Console.WriteLine (e.Message); if (ssc != null) ssc.Close (); } } */ return null; }
public static ActiveIO Open(NetSession assoc_session, Manager manager) { Console.WriteLine("ActiveIO::Open"); if (assoc_session == null || manager == null) return null; Socket ssc = null; try { ssc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ssc.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); ssc.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, SO_SENDBUF); ssc.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, SO_RECVBUF); // 首先使用地址 IPAddress address; if (IPAddress.TryParse(manager.HostName, out address)) { IPEndPoint sa = new IPEndPoint(address, manager.Port); return new ActiveIO(ssc, sa, assoc_session); } else { return new ActiveIO(ssc, assoc_session, manager.HostName, manager.Port); } } catch (Exception e) { UnityEngine.Debug.LogWarning(e); Console.WriteLine(e.StackTrace); Console.WriteLine(e.Message); if (ssc != null) ssc.Close(); } return null; }
//private ManualResetEvent connectDone = null; private ActiveIO(Socket ssc, IPEndPoint sa, NetSession session) { (assoc_session = session).InitSession(); //connectDone = new ManualResetEvent(false); ssc.BeginConnect(sa, new AsyncCallback(ConnectCallback), ssc); }
internal NetIO (Socket sc, NetSession s) : base(sc) { session = s; }
private PassiveIO (Socket ssc, NetSession session, Type t) : base(ssc) { type = t; (assoc_session = session).InitSession(); }
public StreamIO(Socket sc, NetSession s) : base(sc, s) { s.assoc_io = this; s.OnOpen(); }