Skip to content

Commit a973059

Browse files
committed
Merge branch 'master' into factory_pattern
2 parents 78fb5e0 + a5f160c commit a973059

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

chapters/networking/basic-client.textile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ h2. Solution
1313

1414
Create a basic TCP client.
1515

16-
h3. Node.js
16+
h3. In Node.js
1717

1818
{% highlight coffeescript %}
1919
net = require 'net'
@@ -35,10 +35,17 @@ h3. Example Usage
3535

3636
Accessing the <a href="/chapters/networking/basic-server.html">Basic Server</a>:
3737

38-
*$ coffee basic-client.coffee*
38+
{% highlight console %}
39+
$ coffee basic-client.coffee
3940
Opened connection to localhost:9001
4041
Received: Hello, World!
42+
{% endhighlight %}
4143

4244
h2. Discussion
4345

44-
See also the <a href="/chapters/networking/basic-server.html">Basic Server</a>, the <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a>, and the <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server recipes</a>.
46+
The most important work takes place in the _connection.on 'data'_ handler, where the client receives its response from the server and would most likely arrange for responses to it.
47+
48+
See also the <a href="/chapters/networking/basic-server.html">Basic Server</a>, <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a>, and <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server recipes</a>.
49+
50+
h3. Exercises
51+
* Add support for choosing the target domain and port based on command-line arguments or from a configuration file.

chapters/networking/basic-server.textile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ h2. Solution
1313

1414
Create a basic TCP server.
1515

16-
h3. Node.js
16+
h3. In Node.js
1717

1818
{% highlight coffeescript %}
1919
net = require 'net'
@@ -34,12 +34,19 @@ h3. Example Usage
3434

3535
Accessed by the <a href="/chapters/networking/basic-client.html">Basic Client</a>:
3636

37-
*$ coffee basic-server.coffee*
37+
{% highlight console %}
38+
$ coffee basic-server.coffee
3839
Listening to localhost:9001
3940
Received connection from 127.0.0.1
4041
Received connection from 127.0.0.1
4142
[...]
43+
{% endhighlight %}
4244

4345
h2. Discussion
4446

45-
See also the <a href="/chapters/networking/basic-client.html">Basic Client</a>, the <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server</a>, and the <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client recipes</a>.
47+
The function passed to @net.createServer@ receives the new socket provided for each new connection to a client. This basic server simply socializes with its visitors but a hard-working server would pass this socket along to a dedicated handler and then return to the task of waiting for the next client.
48+
49+
See also the <a href="/chapters/networking/basic-client.html">Basic Client</a>, <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server</a>, and <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a> recipes.
50+
51+
h3. Exercises
52+
* Add support for choosing the target domain and port based on command-line arguments or from a configuration file.

chapters/networking/bi-directional-client.textile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ chapter: Networking
66

77
h2. Problem
88

9-
You want to access a service that provides a persistent connection over the network.
10-
9+
You want to a persistent service over a network, one which maintains an on-going connection with its clients.
1110

1211
h2. Solution
1312

1413
Create a bi-directional TCP client.
1514

16-
h3. Node.js
15+
h3. In Node.js
1716

1817
{% highlight coffeescript %}
1918
net = require 'net'
@@ -45,22 +44,24 @@ h3. Example Usage
4544

4645
Accessing the <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server</a>:
4746

48-
*$ coffee bi-directional-client.coffee*
47+
{% highlight console %}
48+
$ coffee bi-directional-client.coffee
4949
Opened connection to localhost:9001
5050
Pinging server
5151
Received: You have 0 peers on this server
5252
Pinging server
5353
Received: You have 0 peers on this server
5454
Pinging server
55-
Received: You have 0 peers on this server
55+
Received: You have 1 peer on this server
5656
[...]
5757
Connection closed
58+
{% endhighlight %}
5859

5960
h2. Discussion
6061

61-
This particular example initiates contact with the server and starts the conversation in the _on 'connect'_ handler. The bulk of the work in a real client, however, will lie in the _on 'data'_ handler, which processes output from the server.
62+
This particular example initiates contact with the server and starts the conversation in the @connection.on 'connect'@ handler. The bulk of the work in a real client, however, will lie in the @connection.on 'data'@ handler, which processes output from the server. The @ping@ function only recurses in order to illustrate continuous communication with the server and can be removed from a real client.
6263

63-
See also the <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server</a>, the <a href="/chapters/networking/basic-client.html">Basic Client</a>, and the <a href="/chapters/networking/basic-server.html">Basic Server</a> recipes.
64+
See also the <a href="/chapters/networking/bi-directional-server.html">Bi-Directional Server</a>, <a href="/chapters/networking/basic-client.html">Basic Client</a>, and <a href="/chapters/networking/basic-server.html">Basic Server</a> recipes.
6465

6566
h3. Exercises
6667
* Add support for choosing the target domain and port based on command-line arguments or from a configuration file.

chapters/networking/bi-directional-server.textile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ chapter: Networking
66

77
h2. Problem
88

9-
You want to provide a service over a network while maintaining a connection with clients.
10-
9+
You want to provide a persistent service over a network, one which maintains an on-going connection with a client.
1110

1211
h2. Solution
1312

1413
Create a bi-directional TCP server.
1514

16-
h3. Node.js
15+
h3. In Node.js
1716

1817
{% highlight coffeescript %}
1918
net = require 'net'
@@ -37,20 +36,22 @@ h3. Example Usage
3736

3837
Accessed by the <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a>:
3938

40-
*$ coffee bi-directional-server.coffee*
39+
{% highlight console %}
40+
$ coffee bi-directional-server.coffee
4141
Listening to localhost:9001
4242
New connection from 127.0.0.1
4343
127.0.0.1 sent: Ping
4444
127.0.0.1 sent: Ping
4545
127.0.0.1 sent: Ping
4646
[...]
47+
{% endhighlight %}
4748

4849
h2. Discussion
4950

50-
The bulk of the work lies in the _on 'data'_ handler, which processes all of the input from the client.
51+
The bulk of the work lies in the @socket.on 'data'@ handler, which processes all of the input from the client. A real server would likely pass the data onto another function to process it and generate any responses so that the original handler.
5152

52-
See also the <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a>, the <a href="/chapters/networking/basic-client.html">Basic Client</a>, and the <a href="/chapters/networking/basic-server.html">Basic Server</a> recipes.
53+
See also the <a href="/chapters/networking/bi-directional-client.html">Bi-Directional Client</a>, <a href="/chapters/networking/basic-client.html">Basic Client</a>, and <a href="/chapters/networking/basic-server.html">Basic Server</a> recipes.
5354

5455
h3. Exercises
55-
* Add support for choosing the target domain and port based on command-line arguments or from a configuration file.
56+
* Add support for choosing the target domain and port based on command-line arguments or on a configuration file.
5657

css/default.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
margin: 0;
1111
}
1212

13+
em {
14+
font-style: italic;
15+
}
16+
17+
code {
18+
font-family: courier;
19+
}
20+
1321
article, header, section, footer {
1422
display: block;
1523
}

0 commit comments

Comments
 (0)