public bool StartServer(int port, ConnectionType type) { Debug.Log("Network::StartServer called. port:" + port); // 리스닝 소켓을 생성합니다. try { // 도달을 보장하는 TCP통신을 시작합니다. if (type == ConnectionType.TCP || type == ConnectionType.Both) { m_tcp = new TransportTcp(); m_tcp.StartServer(port); m_tcp.RegisterEventHandler(OnEventHandling); } // 도달 보장이 필요 없는 UDP 통신을 시작합니다. if (type == ConnectionType.UDP || type == ConnectionType.Both) { m_udp = new TransportUdp(); m_udp.StartServer(port); m_udp.RegisterEventHandler(OnEventHandling); } } catch { Debug.Log("Network::StartServer fail.!"); return(false); } Debug.Log("Network::Server started.!"); m_isServer = true; return(LaunchThread()); }
// public bool Connect(string address, int port, ConnectionType type) { try { Debug.Log("Addrss:" + address + " port:" + port + " type:" + type.ToString()); bool ret = true; if (type == ConnectionType.TCP || type == ConnectionType.Both) { // 도달을 보장하는 TCP 통신을 시작합니다. if (m_tcp == null) { m_tcp = new TransportTcp(); m_tcp.RegisterEventHandler(OnEventHandling); } ret &= m_tcp.Connect(address, port); } if (type == ConnectionType.UDP || type == ConnectionType.Both) { // 도달을 보장하지 않는 UDP 통신을 시작합니다. if (m_udp == null) { m_udp = new TransportUdp(); m_udp.RegisterEventHandler(OnEventHandling); } ret &= m_udp.Connect(address, port); } if (ret == false) { if (m_tcp != null) { m_tcp.Disconnect(); } if (m_udp != null) { m_udp.Disconnect(); } return(false); } } catch { return(false); } return(LaunchThread()); }
//********************************************************************* /// <summary> /// Demo to send packets in three different ways /// </summary> /// <param name="message"></param> /// <returns></returns> //********************************************************************* public static bool Demo() { byte[] bites = { 0, 1, 2, 3, 4 }; string sturing = ""; var sampleClass = new SampleClass(); var transport = new TransportUdp("192.168.1.255", 45678); // Byte array transport.Send(bites); // String transport.Send(sturing); // Class (get serialized before transmission) transport.Send(sampleClass); return(true); }