Can't connect to my google cloud VM instance through tcp using python





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















Situation



I wrote a simple program in python. It's a simple socket chatting program. In my program, the client just connect to an address (ip, port) and send a message, while at this time the server is ready and receives the message and prints it. I can assure the program is correct, since I tried on my computer.



I have a VM instance on Google Cloud Platform, which I can operate through ssh, a simple way provided by google cloud. I can make sure the server is working.



Problem



I start a simple tcp server, python program on my google cloud server. Then I start my client program on my computer. But I get this error:




ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it




or equivalently in Chinese:




ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。




How do I solve this problem and connect to my google cloud server?



I guess maybe the firewall refused my computer's connection, but have no idea how to solve it.










share|improve this question































    1















    Situation



    I wrote a simple program in python. It's a simple socket chatting program. In my program, the client just connect to an address (ip, port) and send a message, while at this time the server is ready and receives the message and prints it. I can assure the program is correct, since I tried on my computer.



    I have a VM instance on Google Cloud Platform, which I can operate through ssh, a simple way provided by google cloud. I can make sure the server is working.



    Problem



    I start a simple tcp server, python program on my google cloud server. Then I start my client program on my computer. But I get this error:




    ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it




    or equivalently in Chinese:




    ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。




    How do I solve this problem and connect to my google cloud server?



    I guess maybe the firewall refused my computer's connection, but have no idea how to solve it.










    share|improve this question



























      1












      1








      1








      Situation



      I wrote a simple program in python. It's a simple socket chatting program. In my program, the client just connect to an address (ip, port) and send a message, while at this time the server is ready and receives the message and prints it. I can assure the program is correct, since I tried on my computer.



      I have a VM instance on Google Cloud Platform, which I can operate through ssh, a simple way provided by google cloud. I can make sure the server is working.



      Problem



      I start a simple tcp server, python program on my google cloud server. Then I start my client program on my computer. But I get this error:




      ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it




      or equivalently in Chinese:




      ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。




      How do I solve this problem and connect to my google cloud server?



      I guess maybe the firewall refused my computer's connection, but have no idea how to solve it.










      share|improve this question
















      Situation



      I wrote a simple program in python. It's a simple socket chatting program. In my program, the client just connect to an address (ip, port) and send a message, while at this time the server is ready and receives the message and prints it. I can assure the program is correct, since I tried on my computer.



      I have a VM instance on Google Cloud Platform, which I can operate through ssh, a simple way provided by google cloud. I can make sure the server is working.



      Problem



      I start a simple tcp server, python program on my google cloud server. Then I start my client program on my computer. But I get this error:




      ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it




      or equivalently in Chinese:




      ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。




      How do I solve this problem and connect to my google cloud server?



      I guess maybe the firewall refused my computer's connection, but have no idea how to solve it.







      python server google-cloud-platform google-compute-engine firewall






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 11:03









      Maxim

      1,573211




      1,573211










      asked Nov 24 '18 at 2:40









      NeoNeo

      286




      286
























          2 Answers
          2






          active

          oldest

          votes


















          1














          This error means that your program is not listening on 0.0.0.0 port XYZ.



          Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.



          Then double check the port number.



          To see if you have something listening run this command (Linux): netstat -at



          Look for a line with your port XYZ.



          When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.






          share|improve this answer































            1














            The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.



            By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.



            One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.






            share|improve this answer


























            • My problem wasn't the one you said. But this is an useful information. Thank you very much still!

              – Neo
              Dec 26 '18 at 5:56












            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454732%2fcant-connect-to-my-google-cloud-vm-instance-through-tcp-using-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This error means that your program is not listening on 0.0.0.0 port XYZ.



            Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.



            Then double check the port number.



            To see if you have something listening run this command (Linux): netstat -at



            Look for a line with your port XYZ.



            When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.






            share|improve this answer




























              1














              This error means that your program is not listening on 0.0.0.0 port XYZ.



              Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.



              Then double check the port number.



              To see if you have something listening run this command (Linux): netstat -at



              Look for a line with your port XYZ.



              When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.






              share|improve this answer


























                1












                1








                1







                This error means that your program is not listening on 0.0.0.0 port XYZ.



                Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.



                Then double check the port number.



                To see if you have something listening run this command (Linux): netstat -at



                Look for a line with your port XYZ.



                When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.






                share|improve this answer













                This error means that your program is not listening on 0.0.0.0 port XYZ.



                Check to see if your program is instead listening on localhost. If it is change to 0.0.0.0 which means all available networks. localhost means do not listen on any network interfaces and only accept connections from inside the computer.



                Then double check the port number.



                To see if you have something listening run this command (Linux): netstat -at



                Look for a line with your port XYZ.



                When you start your program, make sure that it does not error when creating the listener. If you are trying to use a port number below 1024, you will need to lauch the program with root privileges.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 '18 at 4:18









                John HanleyJohn Hanley

                17.5k2734




                17.5k2734

























                    1














                    The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.



                    By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.



                    One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.






                    share|improve this answer


























                    • My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                      – Neo
                      Dec 26 '18 at 5:56
















                    1














                    The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.



                    By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.



                    One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.






                    share|improve this answer


























                    • My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                      – Neo
                      Dec 26 '18 at 5:56














                    1












                    1








                    1







                    The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.



                    By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.



                    One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.






                    share|improve this answer















                    The TCP connection is being refused because the GCP Firewall is indeed blocking it. Therefore, you must create a firewall rule that opens the TCP port for Ingress connections.



                    By navigating to Firewall rules in the VPC network section of the GCP Console, you can create firewall rules or update existing ones.



                    One approach is to tag your GCE instance, and when creating the firewall rule, set the target to be this tag, and as for 'Source filters', the IP of the machine you're attempting to establish the connection from, or simply allow all IPs to connect with 0.0.0.0/0 as the source. Remember to specify the TCP port that needs to be opened.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 24 '18 at 18:32

























                    answered Nov 24 '18 at 18:26









                    MaximMaxim

                    1,573211




                    1,573211













                    • My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                      – Neo
                      Dec 26 '18 at 5:56



















                    • My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                      – Neo
                      Dec 26 '18 at 5:56

















                    My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                    – Neo
                    Dec 26 '18 at 5:56





                    My problem wasn't the one you said. But this is an useful information. Thank you very much still!

                    – Neo
                    Dec 26 '18 at 5:56


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454732%2fcant-connect-to-my-google-cloud-vm-instance-through-tcp-using-python%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini