<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: CreativeGP</title>
    <description>The latest articles on Forem by CreativeGP (@creativegp1).</description>
    <link>https://forem.com/creativegp1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F58836%2Fb1c80931-2f40-4df3-ab36-b435af530028.jpg</url>
      <title>Forem: CreativeGP</title>
      <link>https://forem.com/creativegp1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/creativegp1"/>
    <language>en</language>
    <item>
      <title>Asynchronous, Bidirectional Connected Chat App with SSE in PHP</title>
      <dc:creator>CreativeGP</dc:creator>
      <pubDate>Fri, 27 Jul 2018 09:05:58 +0000</pubDate>
      <link>https://forem.com/creativegp1/asynchronous-bidirectional-connected-chat-app-with-sse-in-php-3o25</link>
      <guid>https://forem.com/creativegp1/asynchronous-bidirectional-connected-chat-app-with-sse-in-php-3o25</guid>
      <description>&lt;p&gt;Yesterday, I created a simple, useless chat app to study the asynchronous bidirectional connection with PHP.&lt;/p&gt;

&lt;p&gt;You can use it &lt;a href="https://cretgp.com/lab/chatter" rel="noopener noreferrer"&gt;here&lt;/a&gt;, and get the source code &lt;a href="https://github.com/CreativeGP/Chatter" rel="noopener noreferrer"&gt;here&lt;/a&gt; (I don't understand enough what it means to disclose the server-side script. I wanna show the beginners an example with SSE and believe there's no vuln and no one wouldn't do something bad :))&lt;/p&gt;

&lt;p&gt;At first, I wanted to learn WebRTC and coded, but the code didn't work because of the hard restriction of my shared server. So, I tried some techs, and I found the &lt;strong&gt;SSE&lt;/strong&gt; works properly.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is the asynchronous / bi-directional connection 🙄 ?
&lt;/h1&gt;

&lt;p&gt;Usually, you use the &lt;em&gt;synchronous&lt;/em&gt;, &lt;em&gt;server-&amp;gt;client&lt;/em&gt; connection while surfing the Internet. This post is the well-explained this type of connections, this is called HTTP.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/antonfrattaroli" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F826%2F6cd54f8d69eecaa954b4e9878f3115ec.png" alt="antonfrattaroli"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/antonfrattaroli/what-happens-when-you-type-googlecom-into-a-browser-and-press-enter-39g8" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;What happens when you type 'google.com' into a browser and press Enter?&lt;/h2&gt;
      &lt;h3&gt;Anton Frattaroli ・ Jul 19 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In contrast to that, &lt;strong&gt;the asynchronous connection allows you to talk to the server without your any actions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And &lt;strong&gt;the bidirectional connection allows the server to talk to you without your any actions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These special connections are required when you want to create a real-time web application with lesser amount of the transferred data.&lt;/p&gt;

&lt;h1&gt;
  
  
  Technologies 😎 
&lt;/h1&gt;

&lt;p&gt;There are several techs to support asynchronous/bidirectional connections.&lt;/p&gt;

&lt;p&gt;What technology will you use when you want to create a chat app? The Websocket Protocol (bidirectional, asynchronous connection between the server and the client) or WebRTC or the basic client-server-database architecture is the common way to do that. I've tested WebRTC and The WebSocket Protocol and these ways didn't work properly in this server due to the hard restriction. &lt;/p&gt;

&lt;p&gt;Let's check them a bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ajax 😋
&lt;/h2&gt;

&lt;p&gt;Asynchronous connection with JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  WebRTC 🤩
&lt;/h2&gt;

&lt;p&gt;This is a group of specifications to do &lt;em&gt;P2P connection (client&amp;lt;-&amp;gt;client, async)&lt;/em&gt;. In PHP, there's some great libraries to do it easily:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hoa-project.net/En/" rel="noopener noreferrer"&gt;Hoa&lt;/a&gt;&lt;br&gt;
&lt;a href="https://reactphp.org/" rel="noopener noreferrer"&gt;ReactPHP&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  WebSocket 📰
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://tools.ietf.org/html/rfc6455" rel="noopener noreferrer"&gt;The WebSocket Protocol&lt;/a&gt; is a protocol to do async, bi-directional connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comet 💫 
&lt;/h2&gt;

&lt;p&gt;This is a hack to manage to allow the server to talk to the client asynchronously, works over HTTP. The point is &lt;strong&gt;keeping from responding for a long time&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;First, the client send the request to the server. Although usually the server respond to it immediately, in this time, the server keeps from responding. Then the server uses the kept response when it has something has to tell the client (event). The client gets the response and send the request again for the next event. Very nice idea!&lt;/p&gt;

&lt;p&gt;However, there even are some problems in Comet. For example, &lt;em&gt;what if the event happens while the previous event is transferred ?&lt;/em&gt; It would cause &lt;strong&gt;a lag&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  SSE 😲 
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SSE (&lt;a href="https://www.w3.org/TR/2009/WD-eventsource-20090421/" rel="noopener noreferrer"&gt;Server-Sent Events&lt;/a&gt;)&lt;/strong&gt; is an another tech to do async, server-&amp;gt;client connection over HTTP. It mightn't be well-known, but the specification is very simple and it's very easy to implement.&lt;/p&gt;

&lt;p&gt;This is an evolved Comet. First, the client sends the request to the server, and the server keeps from responding. When an event happens, the sever send the response but as &lt;strong&gt;a chunk data&lt;/strong&gt;. So the connection won't terminate.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary 👍
&lt;/h1&gt;

&lt;p&gt;I used SSE and it works properly. Now, I can use asynchronous, bidirectional connection even in shared servers!&lt;/p&gt;

&lt;p&gt;Although it's not complete, I think the SSE is a good alternative to the WebSocket. And it should be used more. &lt;/p&gt;

&lt;p&gt;To implement, I recommend you to read the very simple &lt;a href="https://www.w3.org/TR/2009/WD-eventsource-20090421/" rel="noopener noreferrer"&gt;specification&lt;/a&gt; and some great blogs. And you may check my code for your reference.&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>sse</category>
    </item>
    <item>
      <title>Keeping a diary on the Internet</title>
      <dc:creator>CreativeGP</dc:creator>
      <pubDate>Sun, 27 May 2018 01:32:48 +0000</pubDate>
      <link>https://forem.com/creativegp1/keeping-a-diary-on-the-internet-3n1j</link>
      <guid>https://forem.com/creativegp1/keeping-a-diary-on-the-internet-3n1j</guid>
      <description>&lt;p&gt;This is my first post to DEV.&lt;/p&gt;

&lt;h1&gt;
  
  
  Who are you?
&lt;/h1&gt;

&lt;p&gt;I am a fifteen-year-old boy in Japan loves computer programming.&lt;br&gt;
I've made some apps before (you can find it at &lt;a href="https://cretgp.com/project.html"&gt;here&lt;/a&gt;).&lt;br&gt;
And I created a new web application to keep a diary on the Internet once again.&lt;/p&gt;

&lt;h1&gt;
  
  
  CGP Diary
&lt;/h1&gt;

&lt;p&gt;This application is available &lt;a href="https://cretgp.com/diary"&gt;here&lt;/a&gt;.&lt;br&gt;
You can find the repository on GitHub, &lt;a href="https://github.com/CreativeGP/Diary"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This small web application is very convenient to keep a diary ON THE INTERNET.&lt;br&gt;
And this stores the data on your PC only (browser's localStorage), so you can write anything that you want to write with security...&lt;/p&gt;

&lt;p&gt;Keeping a diary is VERY IMPORTANT and meaningful action.&lt;br&gt;
The memory on your brain changes by the second. The hings which your brain judges unnecessary will disappears after few seconds all too soon.&lt;br&gt;
So people have written down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Local vs Online
&lt;/h2&gt;

&lt;p&gt;What do you think about keeping a diary on the Internet?&lt;br&gt;
To be honest, I prefer to keep it in the real world personally.&lt;br&gt;
Let's discuss pros and cons of the two ways to keep a diary.&lt;br&gt;
I wrote the pros only because cons of one way is always pros of the other way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros of writing the date on the Internet
&lt;/h3&gt;

&lt;p&gt;One of the most biggest pros is its convenience.&lt;br&gt;
Nowadays, many people wear a device can connect the Internet next their skin.&lt;br&gt;
So, they can write it at ease whenever they want to do it.&lt;br&gt;
And the imformation on the Internet never dies theoretically. As long as the data is stored on a server, you (anyone if you want) can read the diary forever.&lt;br&gt;
Furthermore, it's easy to look back over the past by reading the diary.&lt;br&gt;
Things in the real world rots anon and you may forget the places stored the stacked diaries.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Pros of writing the date in the real world
&lt;/h3&gt;

&lt;p&gt;As I wrote above, the way uses the Internet is convenient because people can write a diary whenever they wanna do.&lt;br&gt;
However, for those don't have portable devices or if you want to write a diary &lt;em&gt;whenever&lt;/em&gt; in a true sense, this way is more suitable.&lt;br&gt;
And the things in the real world have unlimitted imformation.&lt;br&gt;
Shape of the letter, sort of the paper or the ink, and so on. &lt;br&gt;
It is very fun to examine those metadatas when you read the diary and look back over the past.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Anyway, I recommend keeping a diary in either way.&lt;br&gt;
And, if you decided to store it on the Internet, &lt;em&gt;you must use this application :)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
  </channel>
</rss>
