<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by HuanTing Chen on Medium]]></title>
        <description><![CDATA[Stories by HuanTing Chen on Medium]]></description>
        <link>https://medium.com/@natasi.chen?source=rss-524acb061348------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*34aMTPjcZjOfuD73.</url>
            <title>Stories by HuanTing Chen on Medium</title>
            <link>https://medium.com/@natasi.chen?source=rss-524acb061348------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:51:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@natasi.chen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Start/Stop Compute Engine Instance from Cloud function]]></title>
            <link>https://medium.com/google-cloud/start-stop-compute-engine-instance-from-cloud-function-bf9ae5199609?source=rss-524acb061348------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf9ae5199609</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[compute-engine]]></category>
            <dc:creator><![CDATA[HuanTing Chen]]></dc:creator>
            <pubDate>Fri, 26 May 2017 14:57:47 GMT</pubDate>
            <atom:updated>2017-09-20T00:46:08.371Z</atom:updated>
            <content:encoded><![CDATA[<p>I design a web service that will running on Google Compute Engine to do some long-time data processing task. The data will be stored at Cloud Storage and service on Compute Engine will get the data from Cloud Storage. After processing, the service will save the handled data back to Cloud Storage. And also, the service is not frequency used.</p><p>If we start a instance of Compute Engine, it will start to consume our resource. For cost efficient purpose, I need to minimize the waste. So, I start to survey is there any way to start the compute engine only when we need it.</p><p>After digging from Google Cloud Platform documents, I found:</p><p><a href="https://cloud.google.com/compute/docs/tutorials/nodejs-guide">Using the Node.js Client Libraries | Compute Engine Documentation | Google Cloud Platform</a></p><p>This library allow us to access Compute Engine! I decide to change my system design to: When data upload to Cloud Storage, it trigger the Cloud Function. The Cloud Function send command to start Compute Engine to process the data. After processing, Compute Engine trigger a Cloud Function event to stop the Compute Engine itself. By this design, we can stop our VM to save money while it need not to be used. That is, only enable VM when it need!</p><p>For Cloud Function, I create two function:</p><p>Start Compute Engine:</p><pre>var http = require(&#39;http&#39;);</pre><pre>var Compute = require(&#39;@google-cloud/compute&#39;);</pre><pre>var compute = Compute();</pre><pre>exports.startInstance = function startInstance(req, res) {</pre><pre>    var zone = compute.zone(&#39;<strong><em>instance zone here</em></strong>&#39;);</pre><pre>    var vm = zone.vm(&#39;<strong><em>instance name here</em></strong>&#39;);</pre><pre>    vm.start(function(err, operation, apiResponse) {</pre><pre>        console.log(&#39;instance start successfully&#39;);<br>    });</pre><pre>res.status(200).send(&#39;Success start instance&#39;);</pre><pre>};</pre><p>package.json:</p><pre>{</pre><pre>&quot;name&quot;: &quot;sample-http&quot;,</pre><pre>&quot;dependencies&quot;: {</pre><pre>&quot;@google-cloud/compute&quot;: &quot;0.7.1&quot;</pre><pre>},</pre><pre>&quot;version&quot;: &quot;0.0.1&quot;</pre><pre>}</pre><p>Stop Compute Engine:</p><pre>var Compute = require(&#39;@google-cloud/compute&#39;);</pre><pre>var compute = Compute();</pre><pre>exports.stopInstance = function stopInstance(req, res) {</pre><pre>    var zone = compute.zone(&#39;<strong><em>instance zone here</em></strong>&#39;);</pre><pre>    var vm = zone.vm(&#39;<strong><em>instance name here</em></strong>&#39;);</pre><pre>    vm.stop(function(err, operation, apiResponse) {</pre><pre>        console.log(&#39;instance stop successfully&#39;);</pre><pre>    });</pre><pre>    res.status(200).send(&#39;Success stop instance&#39;);</pre><pre>};</pre><p>Testing these functions and you will see your instance start/stop. This article is some try of my interesting. It may not be useful for a real system design, but it will save money for me!</p><p>For now, I did not finish the complete flow of the design, so maybe the design of my service will be changed again after understanding more about Google Cloud Platform. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf9ae5199609" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/start-stop-compute-engine-instance-from-cloud-function-bf9ae5199609">Start/Stop Compute Engine Instance from Cloud function</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Node.JS Websocket Server on Google App Engine]]></title>
            <link>https://medium.com/google-cloud/a-node-js-websocket-server-on-google-app-engine-c6c32a486e9a?source=rss-524acb061348------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6c32a486e9a</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[app-engine]]></category>
            <dc:creator><![CDATA[HuanTing Chen]]></dc:creator>
            <pubDate>Wed, 10 May 2017 09:11:13 GMT</pubDate>
            <atom:updated>2017-05-12T15:40:50.826Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I implement a websocket server to demo some iOS feature. That server is originally run perfectly on my local side. After some testing, I decide to move the websocket server to google cloud platform to get public ip for demo purpose.</p><p>This is my first time using App engine and it really take me a lot of time.</p><p>Here are some simple steps for deploy a web socket to GAE.</p><p>First, register google cloud platform, now it provide 300 free trail for testing its’ cloud services.</p><p>After registry, Clicking App Engine and run the official quick start tutorial step by step.</p><p>OK. now we have ability to deploy node.js projects to App Engine.</p><p>Then, clone a websocket sample from:</p><p><a href="https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/websockets">https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/websockets</a></p><p>This is an example from google. It shows how to implement websocket on app engine.</p><p>So, we clone the project in gcloud console and deploy and everything will be fine?</p><p>NO. we need some modification.</p><p>First, modify app.yaml:</p><blockquote>#vm: true</blockquote><blockquote>env: flex</blockquote><p>And Please pay attention to the end of this file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*Cg8aThbSOkWja4hmIsqv4A.png" /></figure><p>This part is very important.</p><p>And then, enable the port 65080 for your firewall via the command listed in README</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*9wF-YIeAa9csNjnOhewTHw.png" /></figure><p>After this, just deploy to App Engine and everything will really be fine this time.</p><p>After deploy, we will get an URL like:</p><p><a href="https://{project/">https://{project</a> name}.appspot.com</p><blockquote><strong>Replace https to http</strong> since websocket on App Engine is not support secure mode now.</blockquote><p>Then, launch the new url started with <strong><em>http</em></strong>:// and try the websocket now!</p><h4>Note: App Engine preview mode is not work for websocket in my test.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6c32a486e9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/a-node-js-websocket-server-on-google-app-engine-c6c32a486e9a">A Node.JS Websocket Server on Google App Engine</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift websocket tutorial (with Node.js server)]]></title>
            <link>https://medium.com/@natasi.chen/swift-websocket-tutorial-with-node-js-server-43ce68910b41?source=rss-524acb061348------2</link>
            <guid isPermaLink="false">https://medium.com/p/43ce68910b41</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[HuanTing Chen]]></dc:creator>
            <pubDate>Thu, 27 Apr 2017 14:38:18 GMT</pubDate>
            <atom:updated>2017-04-27T14:38:18.121Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I am developing an iOS app that connected with a websocket server with Node.js. Before this, I have no experience with Node.js and websocket. This tutorial will show a simple websocket server and an iOS client.</p><p>First, let’s talk about iOS! After some searching, <em>Starscream </em>is my final decision for the websocket lib. Why? Oh~no special reasons, just because it’s really easy.</p><p>Here is the link for github:</p><p><a href="https://github.com/daltoniam/Starscream">https://github.com/daltoniam/Starscream</a></p><p>Just install from CocoaPods.</p><p>After installation, import the lib:</p><pre>import Starscream</pre><p>Refer to the sample of <em>Starscream</em>:</p><p><a href="https://github.com/daltoniam/Starscream/blob/master/examples/SimpleTest/SimpleTest/ViewController.swift">https://github.com/daltoniam/Starscream/blob/master/examples/SimpleTest/SimpleTest/ViewController.swift</a></p><pre>var socket = WebSocket(url: URL(string: “ws://localhost:8080/”)!, protocols: [“enter_any_string_here”])</pre><p>The string “<em>enter_any_string_here</em>” need to match with the protocol defined on server</p><p>OK~We have done the iOS client! Next, let’s see server!</p><p>Before this I have no experience about any backend/node.js/server. So in this article I will show a workable node.js server on Mac. But I am not sure if is good enough or is there any issue in this server. I will keep studying this part.</p><p>Thanks for Homebrew. Install node.js on mac is very easy. Just open your terminal and type:</p><p>brew install node</p><p>Everything necessary are installed! Then, create a folder to put your node project. Type on terminal:</p><pre>npm install websocket</pre><p>This will install websocket for this node project. The websocket on Node.js is reference from:</p><p><a href="https://www.npmjs.com/package/websocket">https://www.npmjs.com/package/websocket</a></p><p>For quick testing, we can copy the server sample code from the link. And notice that:</p><pre>var connection <strong>=</strong> request.accept(‘echo-protocol’, request.origin);</pre><p>Change “<em>echo-protocol</em>” to “<em>enter_any_string_here</em>” that defined in client side.</p><p>OK. We have done the server and client. Let’s test it! Open terminal and go to the node.js project folder:</p><pre>node your_server_code_file.js</pre><p>Then, the server will run and you can see some information on the screen.</p><p>Open your client app, it should connect to the server now.</p><p><em>This article is a very simple tutorial for Swift websocket and Node.js websocket server</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43ce68910b41" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>