public IEnumerator closeSocket()
    {
        // check that there's a socket to close
        if (this.activeSocketState == state.Closed)
        {
            ClientInstructions.screen.text = "ERROR: called close without any sockets opened";
            // Debug.Log("CLIENT: \"ERROR: called close without any sockets opened\"");
            yield break;
        }
        else if (this.activeSocketState == state.Created)
        {
            // update appropriate status variables
            this.activeSocketState = state.Closed;
            this.activeSocketType  = socketType.None;
            int closedPort = this.activePort;
            this.activePort = 0;

            // present feedback
            ClientInstructions.screen.text = "closed socket";
        }
        else if (this.activeSocketState == state.Bound)
        {
            // update appropriate status variables
            this.activeSocketState = state.Closed;
            this.activeSocketType  = socketType.None;
            int closedPort = this.activePort;
            this.activePort = 0;

            // present feedback
            ClientInstructions.screen.text = "closed socket on port " + closedPort;

            // do close transformations
            // a. retreat socket back into port box
            while (this.originalSocketPos.x - this.activeSocketObject.transform.localPosition.x > 0)
            {
                this.activeSocketObject.transform.Translate(Vector3.right * .001f);
                yield return(null);
            }

            // b. show port cover
            this.transform.Find("Client Ports").transform.Find("Port Cover " + closedPort).gameObject.SetActive(true);

            // c. move socket back to port 1
            this.activeSocketObject.transform.Translate(Vector3.forward * (closedPort - 1) * this.spaceBetweenPorts, Space.World);

            // d. hide socket
            this.activeSocketObject.transform.Find("UDP Socket").gameObject.SetActive(false);
            this.activeSocketObject.transform.Find("TCP Socket").gameObject.SetActive(false);
        }

        // mark off the checklist
        foreach (GameObject obj in checkmarks)
        {
            if (obj.name == "Checkmark (ccl)")
            {
                obj.SetActive(true);
            }
        }
    }
Ejemplo n.º 2
0
    // shared functions


    public IEnumerator createSocket()
    {
        // if there's already an active socket, send an error message
        if (this.activeSocketState != state.Closed)
        {
            ServerInstructions.screen.text = "A socket is already in use. No need to create another one on this module.";
            // Debug.Log("SERVER: \"ERROR: A socket is already in use. No need to create another one on this module.\"");
            yield break;
        }


        // ask user which type of socket to create (TCP or UDP)
        // string numpadInput;
        // do {
        //     ServerInstructions.screen.text = "SERVER: Choose a socket type: (1) UDP (2) TCP";
        //     Debug.Log("SERVER: \"Choose a socket type: (1) UDP (2) TCP\"");

        //     // clear the numpad buffer
        //     this.clearNumpadBuffer();

        //     // wait for the numpad buffer to be ready to read
        //     while(this.bufferReadyToRead != true) {
        //         yield return null;
        //     }

        //     // record and clear the buffer inputs
        //     numpadInput = this.clearNumpadBuffer();

        // } while(numpadInput != "1" && numpadInput != "2");


        //  // make the socket visible, update appropriate status variables
        // if (numpadInput == "1") {
        //     this.activeSocketType = socketType.UDP;
        //     this.activeSocketObject.transform.Find("UDP Socket").gameObject.SetActive(true);
        //     this.activeSocketObject.transform.Find("TCP Socket").gameObject.SetActive(false);
        // }
        // else {
        //     this.activeSocketType = socketType.TCP;
        //     this.activeSocketObject.transform.Find("UDP Socket").gameObject.SetActive(false);
        //     this.activeSocketObject.transform.Find("TCP Socket").gameObject.SetActive(true);
        // }

        this.activeSocketType = socketType.UDP;
        this.activeSocketObject.transform.Find("UDP Socket").gameObject.SetActive(true);
        this.activeSocketObject.transform.Find("TCP Socket").gameObject.SetActive(false);
        this.activeSocketState = state.Created;

        // present creation feedback
        ServerInstructions.screen.text = "created a new " + this.activeSocketType + " socket";
        foreach (GameObject obj in checkmarks)
        {
            if (obj.name == "Checkmark (sc)")
            {
                obj.SetActive(true);
            }
        }
    }