ClientScript.socketInit C# (CSharp) Method

socketInit() public method

public socketInit ( ) : void
return void
    public void socketInit()
    {
        try
        {
            socket = new TcpClient(hostname, port);
            stream = socket.GetStream();
            writer = new StreamWriter(stream);
            reader = new StreamReader(stream);
            ready = true;
            Debug.Log("Socket is ready to go!");
        }
        catch(Exception e)
        {
            Debug.Log("Error setting up the socket: " + e);
        }
    }

Usage Example

    private void StartGameLoop()
    {

        cs = GameObject.Find("ClientScript").GetComponentInChildren<ClientScript>();
        //WWW results = cs.GET("http://answers.unity3d.com/questions/208309/get-request-wrapper.html");
        // Debug.Log(results.text);
        //depending on the data we are polling, we will be making different get requests

        //  var N = JSON.Parse(results.text);

        //two get requests -> one to request for new names to sacrifice and one for a status check and confirmation to the server
        Debug.Log("Starting TCP socket connection");
        cs.socketInit();
        // cs.writeSocket("test!");

            String str = cs.readSocket();
            while (str == null)
            {
                Debug.Log("str is null");
                str = cs.readSocket();
            }
            Debug.Log(str);
        
        cs.closeSocket();
    }