IEnumerator Start()
    {
        Cosocket sock = new Cosocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        sock.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8999));
        sock.Listen(0);

        Cosocket    clientSock = null;
        IEnumerator accepting  = sock.Accept();

        while (accepting.MoveNext())
        {
            if (accepting.Current == null)
            {
                yield return(null);

                continue;
            }
            clientSock = (Cosocket)accepting.Current;
        }

        byte[] buffer = new byte[256];
        yield return(StartCoroutine(clientSock.Receive(buffer)));

        Debug.Log("Received: " + new ASCIIEncoding().GetString(buffer));
    }
Example #2
0
    IEnumerator Start()
    {
        Cosocket sock = new Cosocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        yield return(StartCoroutine(sock.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8999))));

        yield return(StartCoroutine(sock.Send(new ASCIIEncoding().GetBytes("Hello, world"))));
    }