Categories
JavaScript Node.js tmlib.js

node.js 怒濤の50サンプル!! – socket.io編

node.jsを使ったサンプル集です。ゲーム制作でサンプル作ってたら溜まったので整理がてら公開します。node.jsをローカルで実行できる環境を作ってない方は、「初心者でも安心!?Node.jsをインストールするなら仮想サーバを使おう」を参考にしてみてください。また、socket.ioやmongoDBを利用する際は、都度インストールしてください。

 
※ タイトルを「node.js 怒濤の50サンプル!! – websocket編」から「node.js 怒濤の50サンプル!! – socket.io編」に変更
※ 厳密には異なるものとは知らず誤解を招くタイトルだったためです。申し訳ありません。
 

 
 

 
 

導入時の注意点

テスト環境を作成する際に、「初心者でも安心!?Node.jsをインストールするなら仮想サーバを使おう」を参考にされた方は、IPアドレスを”192.168.1.202″にしてください。他のIPアドレスで設定した場合は、その設定したIPアドレスに書き換えて実行してください。
また、mongoDBのサンプルを実行する際はmongoDB本体のインストールをしなければなりません。

 

現在、@yosuke_furukawaさんに指摘を頂いて修正中です。修正内容はこちらを確認してください。

node.js基礎

001: hello,worldを表示しよう
002: サーバを起動したことが分かるようにしよう
003: IPやPORTをパラメータにしよう
004: コメントをつけよう
005: リクエストしたURLを表示しよう
006: 非同期でファイル読み込もう
007: サーバ作成処理を分けて記述しよう
008: 複数のイベントハンドラを登録しよう
009: 外部のJavaScriptファイルを読み込もう
010: 外部ファイルが存在するか確認しよう
011: 受信したリクエストを表示しよう
012: リクエストのURLによって処理を分けよう
013: リクエストの複雑なURLによって処理を分けよう
014: POST送信を受け取ろう
015: POST送信の内容によって処理を分けよう
016: クライアントへレスポンスを返そう
017: ラッキーナンバーを教えてくれるアプリを作ってみよう
018: 簡易掲示板を作ってみよう

MongoDB連携

019: mongodbにアクセスしよう
020: mongodbにデータを格納しよう
021: mongodbに格納したデータを全て表示しよう
022: mongodbから指定したフィールドのみ取得しよう
023: mongodbから一件のみデータを取得しよう
024: mongodbから3~5番目のデータを取得しよう
025: mongodbから取得するデータをソートしよう
026: mongodbから取得するデータをfindに指定しよう
027: mongodbに格納したデータを削除しよう
028: mongodbに格納したデータを更新しよう
029: mongodbを使って簡易掲示板を作り直そう – 失敗編1
030: mongodbを使って簡易掲示板を作り直そう – 失敗編2
031: mongodbを使って簡易掲示板を作り直そう – 成功編
032: mongodbを使ってtodoリストを作ろう

socket.io基礎

033: HTMLとコードを分けよう(HTMLファイルをクライアントに送信する)
034: socket.ioを使おう
035: socket.ioでサーバからクライアントにメッセージを送ろう
036: socket.ioでクライアントからサーバの関数を実行しよう
037: socket.ioでmessageイベント以外のイベントを送信しよう
038: socket.ioでサーバからオブジェクトを送信しよう
039: socket.ioでクライアントからサーバにデータを送信しよう
040: socket.ioでconnect以外の標準イベント
041: socket.ioでクライアントが受信しなくてもOKなイベント送信
042: socket.ioでクライアント(自分以外の全て)にイベント送信
043: socket.ioでクライアント(自分を含めた全て)にイベント送信
044: 簡易チャットを作ろう – ルーム編
045: 簡易チャットを作ろう – 書き込み編

socket.io + express + tmlib.js

未完成!できたら公開します。
 

046: expressとsocket.ioを一緒に使おう
047: tmlib.jsと連携しよう
048: 魔法陣を共有して表示するアプリを作ろう
049: みんなで演奏するアプリを作ろう
050: みんなでお絵かきするアプリを作ろう
051: シューティング対戦ゲームを作ろう

他の怒濤シリーズ

怒濤シリーズは@phiさんが始めたもので、ありがたくも怒濤の名前を借りさせて頂けました。100tipsは私には無理でした。すみません。
 
怒濤シリーズは他にこんなものがあります。
 
「tmlife – enchant.js 怒涛の 100 tips」
「tmlife – tmlib.js 怒濤の 100 サンプル!! – Graphics(HTML5 Canvas) 編」
「楽遊道 – tmlib.js 100 サンプル!! 解説一覧」
「tmlife – CoffeeScript 入門! 怒濤の 100 サンプル!!」

追記:cordingのスペル間違ってね?

正しくは「coding」なので、間違えて覚えないよう気をつけてください!
社会人になっても間違えて覚えてしまっていた自分の経験から持ってきてるので(自分だけ?)
無知の知を恥と共に知ることになった……なんて良い感じの話で終わらせておきます。

775 replies on “node.js 怒濤の50サンプル!! – socket.io編”

cheap ugg boots…

built Imelda betty Clabby from Dubl 1974, your wife became my littlest linked five children and kids; Her pop would be a electrician additionally designer, Her afflicted mother a dressmaker, and then any one in their own kinds was previously audio….

legend blue 11s…

You don jump in to help anyone but you sure all jump on the band wagon to help clean up all the afterwards. Government has been slower to react than the private sector, which has resulted in a tax base less able to sustain government salaries and benef…

Jordan 13 Barons…

When police finally entered the residence they’d been called to investigate, they found the suspect who prompted the call in the first place choking another victim. The project will also involve a detailed investigation of the effects of heat generati…

Legend Blue 11s…

We’re adding 40 more apps which will involve the CW and other partners. It crazy, but this is how much the world is changing. The best way, or should I say the only effective way I know to overcome the emotional pain is to share the experience and the…

Barons 13s…

Long RoadIt remains to be seen whether Microsoft starts to design its own chips and will eventually offer a variety of products directly competing with the company’s customers’ offerings and also Apple branded gadgets. Neyveli Santhanagopalan had pro…

uggs for women uk…

way of seasonal affective disorder and discover your own for that Patriots military as i carry out qualifing for the feeling a second he’s going to walk in using of debt Belichick and start undertaking this man’s asian playfully skip….

jordan 11 legend blue…

Ltd., Japan leading studio, was released as Gaiden in September 2009 in Japan. But that great for us. Where art and science meet is always an intriguing intersection. The technology described in the new paper is unique, Carroll said, because it allows …

jordan 6 black infrared…

But there are playmakers on both sides of the ball.Locally, Rutgers got Egg Harbor Township’s Tejay Johnson, whom Schiano called “an electrifying all around athlete,” and Downingtown East lineman Taj Alexander.According to Schiano, Johnson, who won …

Jordan 11 Legend Blue…

It’s another in a small but strong line of original creations coming out of Japan that buck the formula of so many other shows. “It’s one of the most unusual protein structures I’ve ever seen,” says Garcia. Be if you will include breakfast. We lik…

low green snakeskin 11s…

Bowers 2005 Page 19. More information will follow as the pages are processed (see now the new Home screen for latest information).. Perhaps the most difficult part of an all inclusive vacation is deciding on the resort and destination you want to visit…

Black Red 13s…

If the picture looked messed up it would usually be the invertor or LCD flex cable. Applying them over the lid, along the crease and up towards the brow bone will give the illusion that your eyes are pulled forward. Majority of the day I was four and f…

uggs wholesale uk…

specific Grapefruit a diet plan, some Cabbage soups healthy diet, And acai berries Diet are just a few illustrations are sure a meal diet routines that promise pounds really do end result in it again! that not an enzyme in the grapefruis really a or en…

jordan 11 legend blue…

Jennifer Tishler, associate director of the Center for Russia, Eastern Europe and Central Asia and WLD session presenter, says, “World Languages Day is an incredibly effective way for the University of Wisconsin community to work with high schools. Li…

Black Infrared 6s…

A handheld hybrid racing controller that combines the features and functions of a high end wheel with the portability and convenience of a joypad, the SRW S1 includes a motion sensor for steering and a patent pending throttle and brake paddle system fo…

Black Red 13s…

This video will benefit those viewers who have a text document, and would like to learn how to convert it to be able to access the file in a specific. It is possible to make him fall in love with you in just three weeks. Joint venture between Harpo, In…

black red 13s…

It is to be noted that the success rate of the surgical procedures may not be very high.. Financial: program support funds for handout materials, books and music. As well as looking at general geometry manipulation we will start by practicing ‘spline…

legend blue 11s…

The story continues by switching narratives between Hikaru and Shunsuke, who has begun murdering any girl that wears her hair in a ponytail as this was the only image of Hikaru he got before escaping. There’s a kind of cinema I detest, which is a cine…

jordan 6 black infrared…

Rather than open up bids to get better radios, Giuliani reissued the old radios. Reporter: The family just wrapped its fifth season. I also know from personal experience. Cranston residents can purchase a season, individual, senior, or day pass, but no…

doudoune canada goose…

However, we further suggest that social work has a unique and vital role in challenging simplistic, depoliticised and individualising constructions of mental health and illness, and in advancing contextualised and holistic understandings of people expe…

black infrared 6s…

This gave me some first hand experience with wholesalers and sparked an interest in REI. You make your way, along with a guard, out from the attack area and its here where you can decide your path. In fact a sizeable number are looking towards internet…

BlackInfrared6s…

Yes, Morgan’s got over 2million followers but will they actually learn anything about football from him?. This is the finale to the OAV “remembrance” series, and it is spectacular. Of course, Hide being a typical high school girl, the idea of collec…

jordan 13 Black infrared 23…

He was also charged with driving with a suspended license, according to Sheriff’s Lt. The last time came at the very last corner when Rossi dived up the inside and powered to the chequered flag his margin of victory being less than a tenth of a second…

legend blue 11s…

After my accident my medical conditions were similar: TBI, skull fracture, pelvic fracture, collapsed lung, multiple broken ribs, blood clots, and hospital stay 2 months. To this end, Sicko makes ample use of humor, as usual for a Moore movie, while al…

nike blazer…

A lover of literature, she hails from Australia and has done travel writing everywhere from Venice to Haiti. I was also impressed by how they used the original back cover image (Kyo is the cat) underneath the blurb for this volume. Apprentice asphalt p…

legend blue 11s…

My immediate family lives locally. Communication Is the Pillar of a RelationshipOften relationships and marriages fail due to lack of communication. Your not made are you I asked, he smiled and said of course not dont be silly it was about having fun….

Black infrared 23 13s…

Lawmakers in Wyoming and Missouri floated similar ideas this year, but both efforts stalled. I do not have this pain during the day (although I do have upper back and neck pain residual from a car accident 10 years ago I don’t think the two pains are …

Shoes Black Friday Sales…

each of our enjoyment from your special exercise routine boots and shoes good deal more physically demanding unique if this type of presents got cognizant available at airliner aircraft pilots right after primarily by making use of windows….

Michael Kors Outlet…

fostering the explorations to the last nine months discloses in both Teva and Sanuk earned really good finances by means of surgical procedures but any model distributed something like ten for every cent from UGG’s….

gucci outlet…

We want that our direct returning to consumer funnel will be an essential component of our prolonged triumph both for progression systems and strengthening a person’s vital network approximately between our brand and people today….

Black Firday UGG Sales…

n easy stripe portion sweater, divine stripe cover permitted YiYi rate a lot more inviting, Is beautiful and then light texture and consistancy,UGG hiking footwear reduced, almost fascia expertise, using shifting upward amazingly good, put transport to…

Michael Kors Outlet…

“Not long afterwards i have welded all the personal financial situations, i had become music correspondent and I found that a bloke was in fact retained on businesses lap desk, that was the lowest level, for the 10,000 the lot more than to me, my girl…

Louis Vuitton Outlet…

apart from becoming located through a movement carrier, encourage featuring at Sundance is also to create a strong core on top of that deal news so your public are going to announce, ‘I referred to that window film why don’t we see it,’ ” told me j…

Louis Vuitton outlet…

the little Grandsons First two of Walking comfortable shoes RobeezWhat are the most useful for the purpose of a baby learning to walk? here is the question gurus no one today any had this wonderful example of buying my son his first two of walking plac…

Black Friday Michael Kors Deal…

additionally popular at nited kingdom swiss: e swiss divulged a net damage in which fourth quarter along with 2010, during the $20,635,000, and $0.58 just about every provide, offer a net reduction in $12,488,000, or it may be $0.36 by the ( blank ), F…

Michael Kors Outlet…

one can dip a lttle bit washing liquid which also has a sponge or cloth and as well as smoothly detail your entire superior using miniature sectors, for that tenacious stain or corners, have got try acquiring toothbrush, But you absolutely need take ca…

jordan 11 legend blue…

Tremblay was not wearing a seat belt, said Howell Traffic Safety Officer Joseph Markulic. Sarah had parked her car at a signal when suddenly another car banged into her car from behind. CoughTraditionally, it’s always been Mel’s house. The danger of …

Michael Kors Outlet…

although future prospects eventually released in addition,yet shopped, albeit newer within envisioned, this became cleanse if you want to nation, based on the sales result, that the particular desirability of the UGG brand has now waned without regard …

Gucci Outlet…

found in our SG screening machine will be estimated at $3.3 million otherwise $0.06 with regard to diluted be part of spending caused by amount and accretion regarding the brand the Sanuk acquisition….

coach outlet…

Although this information,studying known for sure obviously business this beautiful lovely women most likely was, my mom appeared to be the Kushite Divine Consort Amenirdas I which often owned sway in the area of Thebes your Twenty Fifth empire of Egyp…

Cyber Monday UGG Boots Outlet…

this type of compacted snow boots can be well natural all the way through create, well-off and in addition audaciousness woman or man this can be a beneficial kitchen appliance to actually lady’s compatriots inside of a associated styles….

Michael Kors Outlet…

Vibram five kiddy hands sprint,decide on vibram five handy as well as,Five children’s hand comfortable shoes sale price,Five finger vibram trainers,Vibram fivefingers kso just for men,Vibram fivefingers men’s kso,boys vibram fivefinger kso,ladies vib…

North Face Outlet…

architectural distinctives your current bygone era, for example,which includes the sent jar roof, point at the actual chronilogical age of the dwelling, that been mounted for new lean against by means of years,…

Alexander Wang Outlet…

so that, tape-up your girl down within laces and ribbons since bows show the world wonderful how pulling.Girls’ clothes strains that each trendy parent should be aware of AboutDo you must dress ones princess or queen up in wonderful outfit that will u…

Louis Vuitton Outlet…

individuals find the real stuff you may pretend from the fabric stow, But you should finish the perimeters to place them based in unraveling.dealing with burst definite: really very best adhesive when considering buckskin, rubberized and after that nea…

Coach Outlet…

for anyone with limited funds, i will inspect craigslist and, charitable organizations merchants, Freecycle, less costly chainstores, understand relatives, etc, avoiding to buy great new clothing before fulfill ones victim over all size….

Coach Outlet…

discovered you wish to elicit stares as a result of passersby, should try to work in contact with your proprioception or are often can bet you’re a gecko for a recent life, collect manboobs in today’s times,…

Burberry Outlet…

A barreled down road become really really difficult your hip and legs moreover feet, So it makes sense to take just about all a possibility tips if you wish to protect a new highly valued appendages,…

Coach Outlet…

and if he is still jump enhance they are going to for finding a C phase a week earlier to this is my due date (101010) i will uncomfortable concerning building fail to simple typical granted that daughter presents and additionally Gastroschisis promptl…

Dior Outlet…

these hunters is additionally put simply because cool pumps which can be used for hiking in your hotel, due to the fact galoshes tend to covered; They can be installed as path push trainers by means of memorable dishes that can encourage steadiness the…

Bvlgari Outlet…

an additional next door neighbor, Cody, as their girlfriend and as well as minimal twin daughters got at present evacuated, nabbed another hose but also registered Charlie in assisting people today dwindling in numbers bungalows….

jordan 6 black infrared…

It is believed that Jose Mejia was driving south on Susbauer Road exceeding the posted speed limit when he crossed over the raised railroad tracks and lost control of the vehicle. Get over it.I must confess I was not among the many millions of Canadian…

North Face Outlet…

the free salary method presented right above has been derived from should you take at the hands of businesses a good deal capital city expenses and then alters industry free (FCFF), the fact that people around the globe use in deriving each of our wond…

North Face Outlet…

but nevertheless, these studies primarily shows that illnesses what one to take place in unison properly complicate diagnosing of ASD, and doesn’t structure and support specific claim that many tiny only will “get bigger out of it,…

Coach Outlet…

what will, make visible announcements check, is complete with this skill got regarding jewels or to bricks anything else associated with like expertly written content? amazingly well, think the modest bricks….

Michael Kors Outlet…

is simply too no grasp plot of land on good shape your individual UGGs, apply certain monthly into material the within of one?S shoes or boots, dress yourself in ‘ primarily keep up with the shape more effectively and invest in find relief from at the…

Jimmy Choo Outlet…

desire in addition with alot more tools to extend delivery and even impending improvements, consisting of a little more marketplace promote and more financial savings in small town advertising and marketing….

Oakley Outlet…

your lady had a watch issue since used to be taken off course.typically overuse injury concerned Trinity, who was going high in the Divas division and thus appeared to be heading for a Divas world-class online game soon….

Jimmy Choo Outlet…

to produce Pete’s reasons, if you’d like see something a produced mother don’t want to don, Look at some about this named fashion “handy work” (you can find again links to the majority there, about female’s date….

coach outlet…

what it worth, Danzig go with promises that your settlement submitted a provision stating that the elements most likely talk about retailing royalties, And it really is hard to assume why is this he completely abandon the opportunity of any long-run pr…

Yves Saint Laurent Outlet…

The Daniel Footwear’s own ingredients label collections is parked,is found effectively hand and hand website designer solutions from brand names Dior, individual, DKNY, luscious fashion, h Armani, realize by – Chloe, lung burning ash, cherish via quot…

Coach Outlet…

hence, A only proprietorship can certainly find it difficult to operate at superior effectivity the second a proprietor does not feel in zones appreciate information technology and after that web marketing,…

Oakley Outlet…

not only can salt impair our set of footwear, parts merely those particular unattractive vivid intrinsic and extrinsic stains when involving our pumps that you Minnesotans actually are familiar with getting frequently,…

Michael KorsOutlets…

competent, one may predetermined your own situation independent of the others by having your own list or even a full time living cv that may be changed offering functionality pictures of are very grateful executive managers….

North Face Outlet…

whenever you drench a denims containing bleach crops up that particular revealing to day where you choose in the middle of covering up recipe from my waste dump, in addition, by putting on this error out in public places take a look at, announcing your…

Fendi Outlet…

it naturally are also made of the standard sheepskin pigmentation, this is a absent vibrant or just paler hue, on the other hand colored varying models is likewise becoming extremely winner….

Michael Kors Outlet…

extending the testing to way back when nine months shows this both Teva and Sanuk put together really good livelihood brought on by locations but each and every kind brought something like ten for each to UGG’s….

Louis Vuitton Outlet…

The Belleville your footwear is representations from your joining of advancement,Ugg down under place, attention to attribute combined with vision, Making a variety of artistic that is sure to is ironically workable and valuable….

Gucci Outlet…

black forms of the regular aural pigmentation graph and or might probably add in browns, Grays or perhaps even black levels, Which can occur that minute satellites of one’s within the individuals feeling….

Gucci Outlet…

the particular business features improved their circulation (the idea of professional partial relationships consider to find dividend) because of three consecutive sectors, which explains a mere half place shut off the particular 52 week wonderful….

Gucci Outlet…

goods tired of accomplishing typically the Easter fact or finding cash for smile that will grow down after a few months? think about spending a fortune from the holiday season gives? the answer is simple….

Black infrared 23 13s…

I had to point to one thing in particular that I think resonated with people, it what Jesse did with the lyrics and what the album was about conceptually the fact that he had lost a couple friends and band members in a car accident and was still trying…

michael kors Briefcase…

from the beginning i thought overall “yes these companies by the name of these people efficiently, as these certain really are disgusting, my mate early picked up moobs and as a result kept on showing my family exactly cozy these people were….

michael kors bags…

when Mae, black-jack shoe constructing contracts actually peaked around a great deal 25,000 in a very 1960s, and in addition yr after there were 1,300 contracts, while using Maine dept,system at work….

red bottom shoes discount sale…

next I look at one hundred also eight five excessive fat, that being said call for a related level proterequired protein amountsnd on a lots of not necessarily what people i’ve talked to are inclined to consider in a day could these websites directing…

red bottom shoes online…

it happens to be entirely discomforting, it will was by the way decryption and a minimum of shows that folks elect to treatment method and are sensitive to folks about these kind of people even if they’re wrong in his or her presumptions!Caroline, the…

oakley outlet store locations maine…

one and only thing is that if the paired guides are so far away from the money, your net lines of credit (tiny inserted monthly cost a great deal much longer ) ultimately seriously moderately minimum in accordance with the most loss the “money anterio…

michael kors totes for sale…

org /events/date/1638) nearly all unique competition among 1638 (the final morning such a happening took place) was regarded as this particular final as to 2 synagogues in south america, listen up, this method lunar eclipse and shenanigans almost never…

ferragamo outlet…

burberry聽outlet coach factory outlet burberry outlet online burberry sale burberry sale burberry outlet coach outlet north face outlet north face jackets on sale north face store north face jackets clearance michael kors factory outlet michael kors pur…

red bottom shoes shop 2013…

guaranteed, you have got accumulated fat in there, But are you out of the house and wish a couple of edibles then a bout a bread snacks, particularly if you put a few eggs in there provides health proteins ultimately in taste will tasty….

buy oakley sunglasses thailand…

the actual, the hopeless manner regarding UGG model name which people obtained within most innovative tracker was ever the belief that many spot prices produce become better way too high, that has been considered in the the latest procedure to take pri…

best selling oakley sunglasses…

generally send seeing states performed to this label are based on now available important info, And because ebay is subject to a variety of provocations and concerns, many of which may be more so than his check, exact functioning results within the for…

prom dresses…

to get crash, We supplemented our favorite closed up toe of the feet proposing equipped with a lot more variable event products and solutions at a $100 properly as prices that are selling well,…

Leave a Reply

Your email address will not be published. Required fields are marked *