WEBVTT

1
00:00.920 --> 00:02.800
Hi everyone.

2
00:03.200 --> 00:14.400
In this section we will talk about the Socket.io and we will use that to build a real time application

3
00:14.600 --> 00:16.120
in the real world.

4
00:16.440 --> 00:22.520
Okay, many real world application are using the socket IO.

5
00:23.560 --> 00:25.120
So what's socket.io?

6
00:25.920 --> 00:30.160
It's just JavaScript library.

7
00:32.240 --> 00:36.040
To achieve the websockets okay.

8
00:36.800 --> 00:39.560
It uses the WebSockets under the hood.

9
00:44.240 --> 00:54.480
Right now I will explain to you why we need Socket.io instead of using the ws package right here in

10
00:54.960 --> 00:56.640
the previous video.

11
00:58.040 --> 01:01.900
Now In previous session.

12
01:01.900 --> 01:07.540
We used the package ws right.

13
01:09.420 --> 01:10.540
What does it mean?

14
01:12.300 --> 01:22.500
Now you can see in previous, every time we need to send and receive the data, we should.

15
01:24.740 --> 01:29.020
Parse it and convert it into JSON.

16
01:29.460 --> 01:29.980
Right.

17
01:30.340 --> 01:34.220
That's the first disadvantage okay.

18
01:34.260 --> 01:36.700
We also need to parse that.

19
01:39.060 --> 01:46.620
The secondly will be is not an event based API okay.

20
01:46.660 --> 01:47.700
What do you mean right now.

21
01:48.460 --> 01:55.580
Every time we send a message we need to code "if" block right here.

22
01:56.380 --> 01:56.860
Right.

23
01:57.260 --> 02:01.920
Let's imagine We have a large application.

24
02:02.120 --> 02:06.040
It means we will have so many people up here, right?

25
02:07.080 --> 02:11.360
And it's very bad idea, right?

26
02:11.400 --> 02:12.880
It's not good at all.

27
02:15.320 --> 02:23.400
So the second disadvantage will be is not a event.

28
02:30.560 --> 02:41.680
The secondly is when the client disconnect, it's not auto reconnect again.

29
02:42.000 --> 02:46.760
Instead of we should manually do that.

30
02:47.760 --> 02:48.800
Let me show you.

31
02:49.200 --> 02:52.200
For example I will click.

32
02:52.240 --> 02:57.480
Now you can see WebSockets is already closing or close by.

33
02:57.940 --> 02:59.060
It means right here.

34
02:59.500 --> 03:05.460
In order to make it work, we should manually refresh the application.

35
03:06.900 --> 03:07.420
Okay.

36
03:08.780 --> 03:12.380
And third disadvantage.

37
03:12.820 --> 03:13.340
Okay.

38
03:13.780 --> 03:20.100
It's not auto redirect recorder.

39
03:20.140 --> 03:20.620
Okay.

40
03:27.820 --> 03:39.100
And that's the some disadvantage about the normal ws module with the help of Socket.io.

41
03:41.140 --> 03:43.540
We will fix all the bugs.

42
03:43.820 --> 03:46.380
We will fix entirely over here.

43
03:47.580 --> 03:53.020
And Socket.io is also add the additional like.

44
03:53.060 --> 03:54.100
The fallback.

45
03:54.740 --> 03:55.260
Okay.

46
03:55.660 --> 04:03.370
Now for example in some browser or some proxy doesn't.

47
04:06.250 --> 04:10.050
Allow use the WebSocket protocol.

48
04:10.490 --> 04:12.970
The socket.io here is automated.

49
04:14.010 --> 04:18.730
Create something called polling long polling.

50
04:23.250 --> 04:25.090
It will automate long polling.

51
04:25.650 --> 04:26.130
Okay.

52
04:26.130 --> 04:29.650
We'll change from WebSocket into the long polling.

53
04:31.290 --> 04:31.730
Okay.

54
04:31.770 --> 04:33.290
That's about the fallback.

55
04:34.450 --> 04:41.170
And it also auto connect when the client is disconnect.

56
04:41.210 --> 04:41.730
Okay.

57
04:43.890 --> 04:45.010
That's very good.

58
04:45.050 --> 04:53.130
And it also provides much more API for example like room okay.

59
04:53.130 --> 04:58.350
We want to create the room In group chat.

60
04:58.990 --> 05:01.270
It's very easy with a socket.io.

61
05:03.230 --> 05:06.590
And for example, we also have a namespace.

62
05:08.230 --> 05:13.390
Okay, in later, I will show you what exactly about namespace.

63
05:14.230 --> 05:21.470
It provides much more API than the normal websocket.

64
05:21.510 --> 05:21.870
Okay.

65
05:21.870 --> 05:22.910
So for that reason.

66
05:25.790 --> 05:30.670
Every time we need to build some advanced or real world.

67
05:32.830 --> 05:39.430
Application with a real time we will use the socket IO.

68
05:39.710 --> 05:41.070
Let me search that for you.

69
05:49.110 --> 05:50.670
Here are the socket Io

70
05:53.230 --> 05:59.490
And if you click on the dependency, it will have something on engine.io.

71
05:59.690 --> 06:03.570
If I click into the engine.io and click on the dependency

72
06:03.930 --> 06:05.370
Now you can see it.

73
06:05.370 --> 06:09.890
Also use the ws module right?

74
06:11.530 --> 06:13.770
And one more thing you should remember.

75
06:14.010 --> 06:21.010
The socket io is not just a library of the WebSocket okay.

76
06:21.050 --> 06:27.330
It uses the WebSocket protocol under the hood as much as possible.

77
06:27.850 --> 06:36.330
But it's not a library about the WebSocket okay.

78
06:37.530 --> 06:44.930
This is the enhanced solution for the real time communication.

79
06:45.770 --> 06:46.250
Okay.

80
06:46.890 --> 06:49.050
So I hope you are very clear right now.

81
06:50.290 --> 06:53.250
And that's for the video.

82
06:53.690 --> 06:55.050
I will see you in the next one.