Transcripts
1. Socket Session1 Overview: And welcome to this. That is, the CPU DB socket programming or mingles as wonderfully knows, using bought C as well as C plus plus. So here in this session, I would be listing what topics we will be covering in this entire goals. So the metaphors, the optic, me will be understanding the basic concepts of socket for grabbing that this Amanullah it john related in order to understand though socket programming. Then, then next. And we've seen DCP architecture, which is also called as natural architecture, also goin as OSI model. So here you see water network components as well as we will see how the shadow in order to bring the socket communication. And we understand this with the real world example. Then the next session we will be seeing that setup, which is required in order to bomb socket communication for both windows as well as B naught. We will also see different socket functions, which is also called as methods for cyber. War declines for Windows and for Linux. And a slight difference in the socket functions for Windows and Linux, we will be seeing you have session, do understand the difference between Windows OS in order to bring socket communication. So we will be seeing what little setup is, therefore windows. And one bin setup is therefore Lena's. So how did they post what header files are required for being those who both on socket obligation and header files are required or Linux. Then we will be seeing what all different socket met parts are there whatsoever. And nine for Windows and robot socket manipulates our net quantity. So that is very slightly friends and the socket methods. So all of these differences we will be seen in that section. Then the next session we will be starting with socket program and we will also execute it. Barred windows as Venice for us. So here writing different programs. So that will be though program socket communication between server and nine. That is simplest cyber at nine Jack from negations we will be seeing and we will also execute them for those. And we will also understand others. Hockey program, o upon SCTP, Archie Cyberduck nine socket communication on the PC, Barbie in those aspects. Only knows and we will be also executing them in this manner, be building all these programs. Then the other session, we will be seeing what are blocking as well as what are non-blocking sockets. And even be writing that program or the scene and will be executing it in order to understand them more. But we will also see how to achieve my declines server. And we will be seeing that our different approaches in order to Obama, I think nine server's socket communication. So the first basic approach, drink what line do though? So you can understand that our clients, which one put on negate salvo and create multiple threads. So that radius decide one thes's and going through that approach. So we will see what are disadvantages are there in using that approach is not recommended to use NAT abroad. And therefore that I'd approaches which began in order to avoid those disadvantageous. So the next approach is to use Basilica. So even see what does select and what is its importance in order to achieve multiplied satellite communication. So people understand it more effective by writing and executing. But Linux operating system. Then we will see also the approach that is to make this occupies Nagasaki and do achieve multi-line I'm negation. So we will write the program and execute it in the nose in order to meet the socket as non-blocking and in order to achieve multi client server communication on so I have the source code for all the socket programs, the giant cohort in this entirely. So you can require, after understanding the food that I had explained sessions. So all of these things, we've already done this and dire cause. I have described it in short. So I had that like I've explained you what each session we're going to topics we will be offering indeed. So let's see. First session, we will be seeing the basics of the socket programming. So this session is dedicated to all amino law, these which are related for the socket programming. Understand the communication between server and blind. We'll be seeing what does socket, what do I type source socket is available. And in socket terminologies related to this domain and what is communication protocol. So all the terminologies related to the socket programming you'll be, you'll be seeing. But all methods are used for the cell wall and marble methods are used for the line in order to well ball socket communication between the server and client. So all the pieces that are related to the socket you'll be covering in this very first session. So this is very much rubric visit in order to start the socket of negations. So the next session is dedicated to the ECP architecture, which is also called as a negative or yard architecture, but still called as OSI model because very important session. So this, this issue. All the network that is netbook components which are required in order to bring the socket communication between solvent lines. So how come components will communicate with each other so that our seven Leo's presence. So compete architecture I have described here and in this session I have gone through lectures, but music foster coil will be listing. But by default this lecture will be distinct. The network layer architecture. So that will be seven components have been different network Leo's. So I'll be explaining you what is the purpose of each layer network IO. So this is very much B6 and you'll be finding it more investing. You'll be understanding how these network components communicate with each other in order to bring socket communication though with this information, with this already days in the first lecture, and we will be covering the second lecture of the same session, which I'll be explaining you that real-world examples and equity sinking with the network layer architecture that is TCP architected avatar of audio. In this lecture, you will understand another real world example, vid.net Leo. So I will explain you how these network components, how these networks play an important role in the real-world example. So this second lecture will clear your all concepts of all the seven Network Leo's of the PCP architecture. The next session that is taught session that would be related to the Windows specific socket sidebar client method. So here I will be listing defense socket server client methods which are used for the Windows operating system. So I'll be sinking it with the, so this is dedicated to that. The next session will be done. Linux specific socket server line against thinking with old. So here again the same thing, but this will be specific to the Linux operating system. That is very minimum difference between poets Rita use for cyber applying what windows as well as for the leader. Then we will be seeing the next session. That difference between the Windows specific as well as the knock specific socket programming Windows operating system. What are my thoughts are that immortal methods or net Bolinas and work on our differences are there between Windows and Linux. There are only few methods which are different. A specific form, Windows and Linux. And there is no much difference will be also seen here in this session. What our header files you have to use if you have two bulk arm socket programming for Windows Operating System and how it is different for Linux operating system. Then we will be seeing what are been setup is required for Windows operating system in order to perform socket programming, what is we build a startup is required, but Linux operating system. Then in this next session that a session six, I have Gvd Windows specific TCP socket programming in C plus plus. So here this, this, this is the basic socket communication between cyber and how will the charting takes place between server and client. And this, this will be seen for the Windows operating system. And we'll be writing the code in C plus plus. So this will help you to write the program on the IDE or doc ID VB using and how the communication takes place in be executing them. And the next session will be though, socket programming in C and C plus, plus what the Linux operating system. So that seems socket programming before the Linux operating system. And when writing the potency as well as C plus plus. So there are two lectures because I've covered in C as well as I have covered it C plus plus. So this is again the program. You'll be writing the code and executing it in for the Linux operating system. So in the next session that a session eight, maybe understanding a HTTP said line publication on TCP. So once you understand this, VCB communication misbehaved covered 467 session for Windows and Linux. Then you've entered, you will understand how this HTTP server nine can also be, communication can also be happened on PCB. So this is our gain, will be doing the program coordinator for before. In this session we understand poster called the concepts how HTTP Apache server communicates with browser Klein on their PCP. So I'll explain you, although things how Apache said what it communicates with client, that is whenever you are giving any link on the browser, any browser it can be, that is Mozilla, Firefox, or Chrome. Then how this request is sent from the client side is from the browser side to that HTTP Apache side-by-side, and how the server responds to this decline in form of the header. So all I have covered in this session, I want what that line does and who said what and how said what are they saying? That is spawns two plane and hold the page gets loaded. What wonder, whatever the user gave any link on the browser that this session will come meet or theatre all the concepts of HTTP server nine publication. So this may be if you go in sequence according to the session, if you bought new session 60, session seven, and then you will go to session eight, then this will be in you because so almost the programming is going to be writing for this. So communication will be similar. Meconium minimum V3. So this USB understanding ones we covered all the sessions and increments or though. So indecision in dedicate about back. Then the next session will be the same thing that about Africa. I'm disturbing about this stupid STDP Cedric nine communication. We'll start this session by VW bus specific execution of the HTTP Apache server client publication in C plus plus. So this cake is required prerequisites. So when you walk through the session, then only you should visit the session. Because this is the understanding how this communication takes place. And after understanding the communication and fanciful, then. If you are having Windows operating system, or you can write a code. What extra dB, Apache server. I have got all our programming and execution or how I should give you a B27 communicates with Klein is D plus plus. So we do the program for that and for the Windows operating system in C plus plus y. So the same programmed by for the Linux operating system in C. So depending upon what operating system you have, if you have Windows, you can go through this session. If you have a mouse, you can go through the session. Session. Given BC, how do I achieve my declines server communication using the socket in Linux operating system. So here, given a recovery while the c. So now very fast lecture, we will be forced what dark bucky as well as non-blocking sockets. Even the also the very first approach in order to obtain month decline several communication at this by using the select function. So even see what a select, select function, how it plays an important role and what ought arguments are there. So the next lecture we will see, we will be writing program and executing it in all using the select function in order to achieve my declines server communication in this man that I even understand all my client server communication or Sybil by that approach, by using the select function. Then in the next lecture, we will be using the different approach in order to achieve my declines several communication. And that is the second approach by making the socket as non blocking. So we will see how to use it. I don't need those are required after understanding this in the lecture three. Then in the lecture four, we will be writing the program and executing it by making that socket as non-blocking. That this thought in this lecture three, since even understand how to make the socket is non-blocking, Well, the eval function is used and what pedometers I used in this lecture by saying this knowledge of it bubbled in lecture three, we will be writing the program and execute them, making the socket as not bumping and how to achieve multi-line I'm negation. So this governing multiple programs in order to achieve my decline cellular communication by different, different approaches. Then last, we've been seeing the application of the socket. So he noted we're going to be seeing the AVR veterans socket cyber line. Are, you're unable to see the fin real-world examples wherein the socket are used. So now in this manner, we will be covering all of these session in this suit against CBR, accompanying each and everything on Windows operating system, as well as for the Linux operating system in C as Venice, C plus plus. So you'll be finding it more interesting. And it is explained with laptop program and execution. Depending upon the Lena's and rainbows. Your goals. I'm not, if you share your reviews as men, as readings as a means of not the meat and been influenced me to publish such on-demand videos. S-bar, your requirement. So Tank you friends. Thanks a lot.
2. SocketBasicsPart1: Welcome to this socket basic session, which is Betty, AS session of this entire goals veteran, I'm make you walk through different topics at is what this socket, what are types of the socket exist? What do I dominant logic are associated? Socket. So as to understand at the socket plug Rami ahead session and why this socket is required. What socket methods are available on Windows and wall? Socket methods are available on the units will be different. So let's start step-by-step. Moving to the very first topic, what does socket? Socket? It is a combination of the two nodes. But our next book, or you can say communication between the two processes. So let me make you understand through digram. Moving to the aims at an adult isn't the definition says socket is a communication between two nodes. So suppose you are having n4, n1, n2, and n3. And since it is a communication between the nodes or whether netbook. So let me name it. So this is one, this is three. And the communication between them, that is. And let us name this as to the internet. It's sold. What does socket? It is a communication between the nodes or wider network that is internet. So yeah, you can see here, we've paid this n1 and n2. These are the nine node and this node three, as I said, when no originally emitted or discuss detail about it ahead actually, so that you will understand what a sidebar, as well as what are the communication which takes place between node one and node three and node two and node is the socket communication is through this socket communication or whether national. So this definition that is a desert communication of blue nodes. You have seen audit their neck over the network. Again, see communication between two processes. So this can be done so processes, client process one, process two. And this is this I will close. Though didn't about deadlines. So what you see here, you will understand better. So he, I'd have dared out, although on the neck book, which is listening on the particular port and having an IP address. It is called as sort of one. So this one actually need the money. So he either side of a mechanism actually one should be listening on particular ordered an IP address. And either it should be sending the connection actually. So the one which is listening, actually this, the side of item mode and the one sending the connection. Actually there would be though client nodes. So these are the client node, that is node one and give it a sender and action, you know. And this North listening actually, so this fort as this side of it should be and this particular port number and it should have an IP address. So suppose you have, you wonder communication between different host machine that has different operating system, different machine. So you know, Prudence, if you are connected or whether it moves, then the IP addresses of dumb machine, some data dual boast machines which are connected or whether netbook much he'd been had one IP address and Adam achievement at that IP address. So if you want socket communication to take place, so one should be aligned, one should be subtle. So this side of art, which you may decide about, the mechanism is that it should be listening. It should be listening to particular port number as well as IP addressable. Human machine is having IP address. Each machine is having IP address. So it should be listening to, it should be listening to particular. You'd see all the mechanisms step-by-step. What is listening in detail and what is this IP address? What is this port number? So just to make you understand, just to visualize, making, visualize what exactly the sunlight as men as clients. So that, that is what I have mentioned. So moving to the next. This is an important note. Each processes that create the socket for the communication. The next point, the two processes can communicate with each other and he bent the socket has the same domain as well as socket type. So don't worry about this address domain and the socket type, all these terminologies and make you understand and further slides. So just understanding that more important or they say that this process is actually missing middle communicate. One to communicate over there. And they measured through the socket. You should have got socket actually created for them. So suppose no one thought that as a client node, have to dock with the southern route or what? This internet. Then we have to create a socket for this nine node. And we have to create the socket for the server mode. And the second about this is saying that if you are creating a socket for the nine volt, let us say node one. If you are also creating the socket for the software that is node three, then the type of the socket. And then presumably the same. So I will make your what is the socket type and what does the centers domain. But just toolmaker, no doubt that findAnswer, Why should have the same address dominates occupied. So let's see what does all of these dominant ideas about. So this address domain, which I thought in previous slide. So if you talk about address Doumani at our food types of dope. And assuming the first one is the unix domain description is that the two processes. But just sharing the common file system, the company gave him the address of the socket. It'll be the character string, which is then entry in the file system. So the address domain, which I've told that is first one is a unix domain though it's a simple thing actually that if the two processes over 90 to communicate to each other by stock will give it a become negating actually through the common pipe system. If he thought with respect to the isolated will be sharing the Scotsman via system. And the other thing is that addresses missionary, be that for this socket with a string data type, that this is about the unix domain actually. And I'm not good. Dipole, the address dominates that infinite domain. So V2, to be seeing this internet domain, you'll be using it, most commonly used actually. So in the, in the probe image and recovery recover unit embeddable miracles is most commonly used. So yet what will happen? Here? The two processes that are running on that host machine will communicate over the internet the same thing, which I don't know about. So that two processes say that node one and node three, because here the n1 is supplying node and the node three. So node, so these two nodes actually the uprising on different machines. And therefore they will become negated or what the internet, if they communicate what they actually meant it this coil, leon having at this domain on infinity homing. And the addresses of the socket of the is-a intended address was my seems simply to say that yeah, that addresses or this machine or that machine that is denoted by the event happening by IP address or IP address of the machine visited me at making a drum. And this set of item ONE, actually, it will have the IP address of the IP address of num machine. The satellite is running. So it is as simple as you can understand and this diagnostics. So V0, V0 making use of intended domain because this is most commonly used. So this is all about entropy data about their internet address will be on Kentucky group it. So this is all about this domain, which we have thought and this socket type. So we have seen in the previous slide actually the important note actually manual process that communicate with each other. Man they are having the same or destroy me and Saint socket type. So now you can understand that if the node is supplying node and node three is a set of unknown. And actually it may have to meet the communication over the socket using the socket between Norman and node v. So they should have the same address domain. So I don't know, should have actually that this domain as the unix domain, if it is having unix domain than 3D cellular known should also have the unix domain. And if you want the indented code, actually which I explained you, then the normal should also having dinner domain as an address. And the node three, there is a lot more detail also have envisaged albinism in dinner. So though they should have the same, either they should have, both of them should have units to me, or they should have, though, infinite. And the second thing is you'd thought should have the same socket right back to the node one and node three in order to vehicle communication over the socket. So let's see what does this socket type actually? There are two types of the socket actually. So that is a positron is just stream socket and the unfunded minus dot datagram socket. So let's see what is this stream socket. So it uses the TCP protocol. So this is a transmission control protocol. So what does broke apart epistemically the cycle, so that I cycled through once actually, which I probably did. So the TCP protocol will have set of rules actually enrich the stream socket will be or being. And yeah, the in-stream socket come it will communicate as a continuous stream of protector. So what, what is the behavior of the stream socket? By stonewall, it uses dark TCP protocol and communication activity either. I'm here, you see the sand actually, if you use Steam socket, therefore the communication will be bidirectional because once that connection is developed, in case of this stream socket continuously belt at a dustbin v3 transport. This happens in case of dots stream socket. And in case of the datagram socket. It uses UDP, is User Datagram Protocol. The entire message will be sent at once. So this is about the datagram socket. So let's see about this TCP protocol and UDP protocol, as I told you, don't look all mean set up rules for this TCP will be set doped roots. It is different than that of the UDP. And we have seen stream socket is continuous electoral stream or productive and be transformed wherein here with message will be sent at once. So now let's see what does this TCP and UDP. So once you see this, TCP and UDP will understand what is the stream socket which you need to be using, and what is the datagram socket.
3. SocketBasicsPart2: Coming to the communication protocol. So this is called as communication protocol, does UDP, user datagram protocol. It is also denoted in this manner that is underscored ins and this soil, that is what the diagram. So what is this you beat as User Datagram Protocol. So yeah, no, the whole message will be runs scored at one time. That is how much to eat in case of the user given input point. And it is not reliable. Because might is not reliable because suppose it is sending the data from one process to another. And suppose C nine descending someday dark windows server data isn't formal packets. That is num bytes. If some data is lost in between from, though neither do those set of OK. In that case, that will not understand as any lost in data from the client to server, and also the client will not be the same day damages lost. You can understand how it does. It is not reliable at all because he had even if the packet is lost, then one so the client will not again, San Diego said What? You've been on board that also collect the survey item o actually that these packets are lost. So this is called as an unreliable. And yet it is connectionless because there is no connection they've loved actually does not go connect actually to the side. But all the node point about this User Datagram Protocol. Because I debate Actually the reason it, this poster, while it won't have the Borden who do without connection actually, therefore, this reduces their time actually that ordered us into some connection. Another thing is that the packet is large, it will not send it a beam. So this is also one thing which will avoid their task actually. So it megacities in it is a lightweight because it wouldn't do such task actually. And also it does not do the editor checking. So that is the metal packets are lost than had been not again, sanded. It will not do though editor connection. It is simply the messages. It will not want that actually above the packet loss and there is no connection. So all these things, when you consider coined as a lightweight because all the stars, it avoid section. And it is also not reliable at all. But it provides broadcasting in case of UDP. So example, the live example of UDP I can tell you is the light multiplayer gaming. I didn't what happens actually in the data from sending from client to server, then this data will not be sand. Actually the reason actually incase of the multiplayer night game because this will, this will avoid actually that disruption or wide this backlog actually are again sending the message sender who received by this mood or affect the game if it is light. So to avoid such cases actually uses by UDP because it does not send the packet. Again. But the next slide, we will see what is this TCP transmission control protocol that is denoted by sock and the school stream. So Yarn poster boy, it will send and receive the byte streams of arbitrarily lead. So the streams will be sent directly from the sender to the receiver, from the client to the server, or vice versa. So the communication can be from climbed solo, nine, vice versa. Better, but we talk about this socket programming. It can be from one, from sender to receiver, from receiver to send or so I dream of the bytes can be send actually in case of this TCP and walk by Plato pipe you can see and the all advice to leave on the architect and delivered in order. So since this TCP be seeing it as a reliable, because by supporting the oil, older by instability in the correct format is going to be transmitted from the sender to receiver, as well as the order actually of the packets. So it's opposes. All data is divided into small, small packets. Packet one, packet two, packet three from the center, it will be sent to the receiver. It is from client to server. So in the receiver that is not said whether it will be the same in the same sequence order and the order in which it was being sent from the client or from the center. So therefore, it is very much reliability. As well as on talking about this ECP, Adobe's mass transient packet loss, it bacause. So don't connection set up and the maintenance. So there's no defined in one closes or visits, the connection or the connection breaks. So it's very much reliably actually some pictures lost. The other end will get to know that there is a financial loss. So also, it is reliable because if some packets are lost, again, the packets can be transferred from the sender to days. Receivable. A heavy weight actually, because all of these tasks that need to do need to resend the data of the data is lost. Then it needs to do the editor checking it sends a current data so that it has to do this while checking the error and rectifying it. So only starts got associated with this TCP. And therefore it is a heavy. So it does not support broadcasting and it is lower than that of the UDP. You can understand why TCP slower because it does this task actually checking the error of rectifying geared for sending the proposal, it, making a connection through the receiver, all these things, task, tactics, time. So therefore it is lower as compared to the UDP, but it is more reliable, more preferred actually depending upon the usage. So depending upon the usage, you can use TCP and you can use UDP. So when you are using HTTP venue or using HTTPS, you know, whenever you are visiting any site actually that is HTTP, using HTTP colon WW, bulldog bond lakebed, and never you give, invest that format. Then this HTTP or HTTPS that is more secure. If you add a HTTP. So all of these HTTP, HTTPS. Ftp, File Transfer Protocol or telnet. Actually all of these things actually they uses this ECP, that is transmission control protocol, and this is the socket V6 actually, now you study more about it. And also since MY dogged about HTTP. So I will also explain you at the very last lecture. Last few lectures actually will be having the programming actually of HTTP using ECB. So even that wasn't C. So simple server client communication using ECP also we will see other unpractical program of distributed using the PCP. How they communicate actually how the browser communicates with Apache server, how this communication happens. Http Slovak nine or whether TCP. So all of these things, we will cover it. So don't get confused. If you, if I talk about this domain and are muted MOOC step-by-step. So let's see actually. So I hope you understood what is this PCP and what does this UDP moving to the next slide. Now, this advice, so also the thing which I mentioned in my earlier slide that men decide when I'm playing me communicate if they are having the same socket pipe and the same address domain. So socket type you have seen stream socket. Server client should have either stream socket to communicate to each other or they should have felt both of them should have the datagram socket to communicate over each other as well as they should have the same. And there is a domain actually either independent domino still means either both of them should have in an unbelievably, either both of them should have units to me. So now coming back to that. Okay. Yes, this one. So decide by the end client actually during socket network application, you have different behaviors. But the general model for creating a streaming CQI, PCB, IP server and client. So what all this describes is that saying that the satellite implying actually we have to develop the socket for both of them. We have seen this in a very on your side also. Do they even have different, different sockets? Actually, if you want to communicate between them, Gaddafi applications or defense sockets are required. And both of them, and I'm creating the socket actually. The second thing that was socket method creation, actually methods or sediment in client socket creation will be the same. So this may even be starting next month. Visit actually different methods which are used while the socket for sedimented client communication, we'll see forming those work element occurred psi u, and in this manner you proceed. So let's see this side, webinar network methods which are used so their defense socket server methods and different sock socket blind network methods. Now let see. Now also in this methods and pretend you weren't all is busy quarter when goal machine, what role is present for Linux machines? So just engender to speak. Actually these net movement occurs which is listed for the satellite. Actually, sockets is almost similar and actually quite windows and pointy nose. Only Manon built one for APIs is not. Methods are not present. In case of the Unix list, all of them at once are present in KSR Unix. So let's see. So this socket side where network methods which are used. So what does it mean to be doing and no side avoided site actually to create the socket. Actually, in case of Windows. So windows, we have to initialize w. I will explain you what is a justice. I'm giving you the overview of what, what methods really using detailed discussion in the next session actually goes that and I explain you how, what is WACC, how to initialize it. So this is used to, this method is used in case of Windows. So this is not used in the Linux. The next moment that entices us side-by-side methods, which is a vigil had listed here. The next method is creating the socket for this initialized WSDL and supposed to be done while windows not bother you a Linux. But creating a socket is generous. So all these methods which are listed is general for both Linux as well as one minuss. So creating a socket, actually your degree at a socket on the software side, we have to bind the socket. So now this binder listen, accept all these unexplained you in Nevada lectures that are dedicated to hold action of explaining what methods are present. What I saw was eight and what all parameters? Yes. Opposed to pass to it. What is the functionality of each of them actually for the celebrate as Melissa Klein site. So by ending the socket, so but I have explained you that Panama said when he took lie, how communicate o the data offline. So why shouldn't listen to particular port number, an IP address? That is, you see this, bind, the socket means we have to bind to particular port number. Going with real explained in detail in the next lecture. And listen to those outside of vitamin B, listening on that socket, once it is bind to particular port number, it is any displacement on IP address. It is having one IP address. It will listen on that socket that is buying to decide what to listen. And then it will simply connected ones, that blindness AND connection, then it will exit the connection. So it has to do these task actually before accepting. It has to bind to particular ODE number. It has to listen to that port number and explain in detail. And then it has, then it is, it is a block accepting that connection, and that connection is accepted, then it is capable of sending the data to client and receiving the data from that mine. And another method is last method is disconnected us losing actually the connection. So this order methods, these all processes happens in gaze on the sidewalk outside, all found on functionality we have to do actually. And boy, windows extracting is we have to initialize Ws risks. These things are common to Linux as well as Windows completing socket to disconnection. Well, no, let's move on to understand to see what methods are there for the client side. Again, the same thing. We have to initialize Ws in case offline referred also. So this is UNEP on Windows, it is not applicable for Linux. We have to second thing, we have to create a socket sold streaming. I know socket creation. We have to do what the client as well as for the servo since these are the different application processes leaving him different different sockets. Created actually by, as I told you, four, said, What am I going to communicate? The socket should have the same socket data type. We have seen the socket socket type. Actually, it can be seen, it can be supported by Akos. Actually we have seen the stream socket types. You have senior friends, stream doc socket. It should be having either stream socket on either datagram bought up. The client and server should have the same socket actually. So we have to create a socket. So you can see in lectures actually how to create a socket, how to give this occupied or competitors domain. And then you will understand, then we have to connect. So as I told you this outline, the rule is to just connect to the soul will know how to connect with the solar. Because already the side of it is binding to particular order number and listening to that port number. So with the help of that only though I am will connect to the server. So don't worry about all these functionalities. Just I'm giving you an a what do you do deal? We'll discuss, you'll see in the next lecture which is dedicated to all these macro explanation. And then sending and receiving the demand such cutting through the salvo it escaped had been sending the data as well as receiving the data. And then the last one. So these are other methods for those and my site. So see actually these methods. Now we are done with the socket risks. So what all things Stephen be starting? This is just a null. What do you actually avoid topics we'll be covering Actually, in our row. We'll be covering the OSI model, that is open system interconnect model. This is going to be studying, this is a netbook reference model. It is very much important. It is called ISO network layered block diagram will give you the overview of all the network system. It simplifies actually, your road networks is complex network system into different, different components and describe how these components communicate with each other discipline ParaView. To also get rid of the problem does or you will understand how one day send actually hold the data sent from sender to receiver and vice versa in different, different processes, actually differently by different, different layer Bode diagram. What all things were dot O alleles comes into account. What are the different examples, protocols easily or uses. So this, I have simplified it in very easy manner actually. And this is very much important for all though. College-going students. Thought thresholds for developers, as well as it will clear your basic concepts simply to talk about it. In the next topic, which I'll be covering the sidewalk line and go socket APIs. Since what we have studied here at coincide available for window. So it was a client side for the socket communication that we will be studying in this lecture, you'll be sinking into the Cold War. But ME does what all functions are used in detail. And then we will study what is said about line Linux socket method. And then we build a program for PCP, said about nine socket communication on the board, but you'll be writing the program to communicate. Between the friend forced file using this TCP protocols have of mind and we will see how they communicate, how server communicate with Ty and help. I'm will send a message to server. Howsoever will respond to that line. So this, we will do the practical example, right, but program one by ID and we'll run it. So the next thing, which will be another thing I thought actually this is very much important. So that is a reason I will be covering with its programmable. So since I told you what is HTTP, it uses TCP. So even see this program actually, we'll see what does HTTP and the programming of STDP, so-called encore block ID. So you can understand what is HTTP site of autumn. So you will find it more interesting because day-to-day life. Now the internet is becoming so common to all of you that we are used to it actually be have simply something we have to find actually be available through the Internet. Achilles soldiers always have this thing you will be aware what is HTTP? Simply give HTTP colon or name of the site actually, which you want to visit. Level explained you how the browser communicates, how whatever you give the site name actually on your browser, that it is a Chrome browser, Internet Explorer browser. How it talks to the robot actually idiom how it fetches the data and how you get there. Guitar, on your application level, you write the program actually with the help of the knowledge we have studied, the breeders lecture, identify you as very much easy. Once you just have to start with, you have to write the program with me. And you'll understand embryonic Lecture seven, given what I blocky as well as non-local sockets. And we will be writing a program and executing it in order to understand them much better. In the next lecture, we will be seeing how do achieve multi client server socket communication. So nobody forced to be sick approach using the thread. So that I say everybody said one pieces by using that. And we will be seeing them one by one. What are there in order to avoid those disadvantaged person approaches in order to achieve a decline server socket communication. So here I have divided it interdependence and lectures in order to understand how to achieve my declined server socket communication. So there are two approaches. So in this lecture, we will be seen by the first approach, that is by using the select function. And we will be seeing what is the select function and how you use it, what all humans are required. In this manner, you will see how it brings my declines socket communication. So this lecture is dedicated for that. Then we will be writing the program in the next lecture, the program by using the select function. So here in this lecture we will be understanding what is select function, how you use it. In lecture nine, we're writing a program and by using the select function on the Linux operating system. Lecture ten. Achievement decline server communication by using the second approach. So even that second approach is by making the socket is non-blocking. So we will see how to make socket is non blocking. What all functions are used and what are humans are required. So with this information in lecture, then we will proceed further or lecture lemma that a new write the programs and will be executing it by using the second approach by making the socket is non-blocking. In this manner, we will be seeing how to achieve my declined server socket communication and an inverse operating system. Then the very last lecture, we will see the application or socket. In these areas, socket server, client are used and we will be sinking it within real-world examples that all the socket servers are used. So all these things I have mentioned which we'll be covering, and I have made you walk through all these socket dominant ideas, what all things are necessary for the socket. So VI done for the very first lecture of our compete school socket V6 next BOD POD, this lecture which I have mentioned actually, that is, so this OSI model, net volt reference model, denser, multiplying all these things you will be covering step-by-step. So thank you. Thanks a lot.
4. SocketSession3 Part1 TCP OSIModelPreview: Hi, welcome to the second session of the course that is TCP IP architecture, which is also called as all as I model. Dag is open system interconnect model, also called as network reference model. This will give you the overview of the networking system, explaining you how these components will communicate with each other, how to be transmitted from sender, receiver and this middle basic, your socket unzips DM, So networking. So let's understand these networking and let's understand how become negate. So you will get an overall picture of the socket and its internal components. The, Let's begin leaving the BC, or one of these topics which is mentioned in this slide, that is, what is OSI model and the importance of it. Blog diagram of OSI model B. Then a discussion of the components of this architecture illustrate, illustrating the communication of these components with each other. And finally, we will be seeing real world example to illustrate this OSI model, to illustrate how these networking components communicate with each other. That is the OSI model, which is also called as networking layered architecture. That is also that TCPIP architecture. So let's start with my mom and understand this networking system, how these components communicate with each other. So what do you do in the next slide? What is OSI model? So OSI stands for open system interconnect, which is also gone network with reference model. So this OSI, it will give you the overview of the entire networking system. So it's an oil is to simplify the networking concept into small, small network components and to describe how these network components will communicate with each other. So this is very much helpful him. Or the network techniques Jian Wu troubleshoot the networking problem because it simplifies this negative when they're hoping systems and do small, small components. Explain you how the art of communicating with each other. So that whatever your problem is, that you can troubleshoot which layer this problem occurs and you can exit. So this is how it simplifies it. So this is what I have described in this slide. The another point is that what I mentioned earlier only provide you the overview of entire networking system, but also simplifies the problem of network technician. Who isn't it troubling problem referring in this OSI model, it consists of seven layers. That is the seven components like see what components are present. Though very upper component abelian, which is present in this OSI model is the application layer. So this detail I have described to you, don't worry, I will explain you. What is the application near what is present, all these nodes one by one. And we're going to be seeing also what protocol and status set of bullets all these Leos are using. And later on we will also see how the OSI model view in sync it with the practical example. I will explain you real-world example. And I will explain you how these Leo's bringing the data from sender to receiver. In fact, examples of human understanding. So let's see.
5. Socket Session3 Part2 TCP Network Layered Architecture OSI: This is an application layer that is very topmost. Leo then is the presentation layer, Session, Transport Layer, Network LEO, data link layer and physical layer. So all these things I have described here with the examples actually, but lets see one by one. You can go through it later on and whether digraph, That is architecture. So let's begin with that up earlier. That is application deal. So what does this application? So it provides the user interface. So simply evenly talk about application you can understand application is the one which will help you. Step one, arbitrary user will interact with. So it will provide you the user interface. So whatever action you fall, fall on the application that will be reflected, then it will reach the lowest Leo from topmost Leo. So you use a need to do some action in order to get the appropriate response. So that action which is done, is done on the application component that is present. And that is, that is what about application Leo examples or FTP? No, FTP is used to plans whether phi. So ten net also, you know, we have to connect email applications or other applications. The order is defined. Then the next layer, which comes as a presentation, DO SO what does this presentation Leo? So in this presentation, Leo, whatever I'm motion or data conversion is required in this application will take place on the presentation Leo. So simply decide described here also. It is used to the format the data. So you can compress or decompress, encrypt and decrypt. But Gita, since study deconvolution is required, therefore, it is admin form under Deepa will come 50 companies and Paralympic group. So yet, whatever the formatting the data will be taking place. What application when taking this presentation, Neil and the other data encryption takes place, as well as character sect and wasn't explicit. So example also there. So JPEG, PNG. So you know, these are the hormones also their fixed format. So these are different, different type older format. So you can understand this example itself there TO data encryption takes place data and voyage and takes place in case of JPEG PNG. Yeah, these are different formats. So when we talk about the data format and this presentation layer comes into a gun. So don't worry, I will explain you the real-world example after explaining these layers. And you can sync with all these news. That is presentation, application in oil and in this manner even understanding what really then what is session NEA, session layer, it will write the name itself, says that is the connection you can understand. So it opens and closes session with that company mouthfuls, so it is responsible but opening the session for controlling the session, foreclosing the session that remote post-doc is done in war machine. And so this session, the OED actually, so this session, which of deadlocks that anymore, who knows that is a connection Richard develops with the remote virtual connection. So it butchered by the name itself. You can understand it is not real connection actually need some virtual connection. That is established, so also described as a transport connection less or without any network communication. So you can understand that an ancient exists but without any network communication. So therefore the name watching connection, then the example of the session layer are given, explained you actually, that is, that will illustrate use all the email application. So in the human application manner role, we have to send any funny Buddha remote host. We have to transfer the Pine To the remote host. So what happens at, though pretty pre-established, there was but a CBO bill send the data to the sangha of telling the information about how much the data is received now. So it's one small intervals whenever the file is being transported. In case of the email to the remote host, this receivable tells the sender how much the data is being transported. Now. So that happens at small, small and governments and 3h assemblage and double suppose in between or needle connection gets lost from there down. So that we have not discussed above or below this session layer that is a brand, that is a transport layer. So denote we have discussed about the application presentation and nomial talking sessions. So below procession near that transport layer. So if the connection from the DOM layer, that is transport layer, it is lost, then what will happen in that case? In that case, the watchman connection will be existing. So what you'll connection will not get lost. And an inverter, this session, the audit receives a new transport connection, then sending on the data. Again, extra resume from Reddit was stopped earlier. So this I mentioned he also basically the opening controlling and closing session. It is done by the transport layer which is downward to this session. You can understand what is the session near the spine needs to be corrected spelling. Now. Then when we talk about Euler rotation via so now talking about the DownloadActivity, thinking with the session, we also draw on what is the transport layer. Transport layer. It will transfer the data by the name itself. You can understand, and it has an inbuilt, blue-white, any connection between the host. So it will transfer the data and provides end-to-end connection between the host. So this transport layer, actually, you can see the connection between tablets between the host can be reliable, that is an action or can be unreliable. They're disconnection that soul. I hope so by this reliable and unreliable, you might be understanding we have seen in the reports searching about TCP and UDP, met and B have seen PCPs reliable. Europeans, non-black is unreliable. And we have also seen that TCP is reliable because it is, it will ensure actually all the data is. To the receiver correctly in the correct order that ooh, if some knob I can dislodge, center will notify to the receiver and again the data can be transmitted. So editor predictions also provided it is heavyweight level because all the wood walls in task one error correction for sending the data if the packet is lost and it develops a connection. So all these things happen in case of dough TCP is a reliable connection. We have seen unreliable connection. That is, that is UDP had no error, correction will be banned. And it is not o, it is best onboard that even if a packet is noisy, not send a data and not notify once you do that, a CBO. So here it is very lightweight. So all these points we have discussed, all this transport layer with the help of their families because are linked to each other. You can see when I talked about the session neared, I was here was what was walking with this DOM near transport layer. Ok. So now because they are communicating with each other, nominate talk about transport here. Nobody who coined his pension that Hale-Bopp network here. So that is again there w. So this transport layer with the help of this magnetically ordered his own IP address, and it builds Sander data. So though data widget receives vigilance transport layer, it receives from the session layer actually it, with the help of the download that data, it will address the data. And so the example which I told you is TCP data connection one and UDP is connectionless. So the next layer which is present is the network layer, which is the downward through the transport here. So what does this network Leo? It is it is it routes that is ramping means giving their direction. So yeah, DO data packets on details Transport sold out means to giving the direction to that packet to which path it should be travelling, that packet should be traveling, so it will be rounding. Datasets will give their direction, will give the RP packet from one path, it should travel along descended to policy, but that this route, so it will, it will, it will again reassemble the packets of data because it sends one packet of the data, one few packets of data from sender to receiver, CBO site, it will reassemble, it will collect all the data together. So this is about the network view. So the main purpose of this demo nuclear is also addressed the packets. So it had been provided their address to the packet, right? That that packet will understand actually through which path it should travel. And through the internet, local bridges and uncle and example is IB. So I also understood this. So it will roll is actually to give direction to the packet that is ramping, name reassemble the packet of the data. And its main purpose is to give the address to the packet so that the packet will understand who which they should pass through. Internet, local bridges and auto example is IP. So the next layer is there data link layer. So what does the data link layer? It does actually, so it is also the next one driver layer using. Because by Dr. Willard because it will also neglect art is a hydrostatic. This is the main network guide which through which you achieved the internet. So this is our device through which you achieve and collect. So it is this, our Leon is not a device, a desert rivalry is a network tribal and because it will control the network card, okay? Now, this data link layer, I need the competitive request as two or more negativity or uses soul, since it will control the network card that would've been an eagle and soda connections. So they're never that or more neural network layer which is using the same network answer your non-equity oldest present at top of this, which we have discussed now. So then do one word, network. It will use the same network card. So how this management when for the White House has access to the network guard will be that is only my neck and network card. But how this excess money provided for the network layer which is present and Egypt and pulling this data link layer. And so he, I don't also the physical addressing of the network and action takes place. It also consist October law about disorder will have described so that you should be knowing each and everything about the CEO. So it comes as to which topology there is internet topology. And it is also used, it also uses are most commonly used network device, that is if uses switch. So this is all about the data link layer. Also does the Italian clear it consist of two sublime, isn't it? So widely otitis, media access control, that is mac sublayers of what does this Amaterasu, It is responsible for the device interaction. This I mentioned your device networking detection. And the second is W at which does Dayton in Kansas, is logical link Leah, suddenly. So this logical link layer, it provides multiplexing and addressing about it. Though we are multiplexing means what? It means. It will, are now, might deepen and walk through appropriate why people exist at different multi-point network. And it can also be transferred, transported, or whether same networking medium. This is what about the multiplexing? So an example of this data link layer, if you see will be the mass source and destination address, as well as the eternal flame. So don't worry about all this. Technical writer, poet is doodling clear. I hope so you understood, just understand it. Going through the network part, it is used to meet an angel connections when I'm when people connections from the network layer using the same network card, it will manage that connection and it fancy store two things present in our debtors, MAC and LLC. Logical link control magazine of a prom is divisive that action and this will provide multiplexing and addressing. So their detail about it, I'll explain you involve real-world example, which I have a lot of the public, these leaders, I have covered the real-world example and I'm explained holders, these Leo's, the sync actually what they will do when I'm in that real world examples. So you will understand what exactly these Leos are mobile. Now, the very last layer is the allele. So this physical layer, it is also called as though it is a network. Also doesn't mean Hyderabad actually brings the network that are different forms of heard of it. It can be also the network cables it hadn't heard and all that. So all these concepts that physical. Yeah. So thank you. Thanks a lot.
6. SocketSession3 Part3 TCP OSIModel RealWorldExample: Hi, welcome to this second session, Part two for this OSI model that is TCP IP architecture. So in fact, in the same session I have discussed about the seven Leo's, which brings the networking system. So how these components, what are these layers are responsible for? And how they communicate with each other. So in this lecture, I will be explaining you that he and God example. And I will be explaining you how these seven Network Leo's video rolling the sailboat examples so that you take a picture how these network Leo's network components one day I had and how they communicate with each other. So let's see this. So here we will be studying the inward examples like this. I simulate a single food order. So yeah, the customer will not make not through their network and place an order with an IPO. Then we will consider that dog customers calling done on both on their distorted and placing an order and that person know, deceives decoy and the customer communicated with the order details what the customer wants. And delivery person then will be going to the address on a stimulant and going to be delivering food. So it will be to see how these Leo's then play a role in them. So let's see a one-by-one. So pastas application, Leo. So Vannevar stellate is submitting a form for silica stoma is interacting with the horn actually do communicate in the details of the order. So yeah, the application so you know, what is the application layer whenever that is an indirection, it allows the user interaction, depending upon this action, it will be responding. So the action is that the customer is making a phone call using the phone to please order. So this is, this, the application layer comes into account and the protocol associated with it are HTTP or HTTPS, then that FTP, as I said, is empty. So all these are the protocols which comes in this application layer soda, customer, using the phone to place an order untimely application. Leon, let us do that interaction with the port. So then next comes is the presentation layer. So what this presentation the IB has studied in the previous lecture, what does it do? It does the form I think, of the data. So it will do the data encryption. So it avoided the formatting required for an application and be done in this presentation layer. So what did we do? Blastocoel or the command which it receives from the application layer of policing. And on the back, it will be unloading the human EVA suit event non-network formula. So what does it mean? It means that definition means that it reporting into some particular format that you said. I understand. So this format should be common to them. So here Similarly in case of example also whenever the asteroid one foo, I'm going to get of the order details like suppose the customer wanted to order some nought. So it has to communicate to that restaurant in person. The language which no customer is using to communicate to that this burden present should be common language. That is, it should be universal, it should be known to them. So that is a reason it will be converting into that format. It will be converting in perfect language. Speaking. The person will be speaking in that language, common to both of them. So that miseries and this presentation layer, it is used to unmoored in that format that is understood by them in order to pack all proper communication. So this gums in this presentation near the protocol used is the D. So we know that the images in different formats, the date back if Pfam NGI bend at our HTML different, that is the page actually the webpage, then the ascii related to third strings. So this is on the protocols which are used here in case of presentation Leo. Now, this session, what does postal cuando session layer do? So in order to transfer the data, that is a packet actually do their destination, this session layer, it should open control and close this session which are there between the end-user application processes are responsible for opening, controlling, and foreclosing decision between different application processes. So Riot is required open-ended session. Do the remote host in order to send data to transmit a packet, it should pass open session, do that remote host. So we know this session near US and what you can actually have seen butanes and abuse through this lecture or this session, second session. So if you this example, Victoria Albert example, by stockholders, customers making a phone call and the restaurant person should receive it. Actually, write your receiver so that the customer can communicate with that receiver. This disorder is dead and unique, new send this ordered. So this communication is required so that receivable again, the information of the order details what all order the customer has faced. So this on because the reason the session, this is very much required. The other end, that is the distorting presenters received a phone call or in order to have this complete successful communication protocol used as RPC, you know, RBC. We have, whenever we have to come communicate through the remote machine actually then that means you need to develop a session between the remote machine. Then this RPC used SQL also do communicate with the database actually to connect to their database. Sql is used, Network is one and it working prices temp one. And this X Windows is used to communicate or whether I gotta get machine. So this is on the session layer comes into account. Now talking about the transport layer. So cluster while the transport layer is to transform the data in between end-to-end. Can it brings out the end-to-end connection promise. Was there the mean also what this transport layer, when it does, it, does it is, it not only ensures how the data should be transmitted, like whether it should be connectionless. Audits should be connection or data that is, TCP should be therefore, an ancient UDP should be therefore connectionist, inorganic side packet all its sole provides no fireball security and validations and provides a security that is acquired one, please. So you know, by N1 is used to secure their data. The suspicious package that is. Which is suspected at some problem with some editor will not be passed to the higher one. So I need a valid packet will be passed. But suspicious bracket, non-key parcel, it provides the buyer wants security. So with deciding how the data should be transmitted, connectional connectionism also provides these features. Then. It also brought there does it provides a quality control? Quality control in the sense. So this has Species packet will not be allowed to pass through the fire. And was Susan's depicted problem is there in the packet. Therefore, it is checking the quality of the packet is not good, not deliver through the firewall. That is the reason it provides this quality control. Now, thinking with a real board, that is, if the food is not good actually, which is being prepared is that I started and it had been an RB deliver to the customers. So this a species four will not be allowed to be delivered to the customer. Thinking with a real world example. So this, as I describe you, this transport layer ancestral two things, two types, statistic, Cp. Here, it will decide that how the data will be transmitted. It will be having an action, it is connection oriented. It will be also reliable that because if somebody dies laws then it will be notified to the receiver also again, it will be transmitted edit that section will also be happening. And this is how Holzer deserve heavy bait because it performs all these activities. Then example or PCBs, HTTP, FTP, SMTP, met as in case of UDP, is connectionless oriented, we have seen that it is not reliable because of some packets are lost and it'll be not notified to the receiver. Again, it will be not send reset. And it it does not bother that it was not directed. So that is a reason it is not reliable. And the life example of this UDP is lying vertically or gaming. So this is some notation that is multi-player. So right, it does not send the packets which are lost because that will be our disruption. In this communication. Again, DWB, WB senate sometime will be taken. So that is a reason or not. It's ended and therefore it should be used in live communication. So this is what happens in case of UDP. So this is a live example. Now talking about them o'clock Leo. So what does this network layer we have seen first took one network layer. We have seen in the earlier lecture, provides routing of the packets. That is, it will decide what direction the packet should go, ooh, what path it should follow. And then we have seen, and we have also seen it is responsible for framing and assembling of the packets. So what neck multi-year provides, it provides the best path to route packets. So best part means it provides of what should be the best path for the group level bar chart, short path. Before actually in order that packet should be sent from the sender to the receiver. And what part is should use, what is a valid OK, so at that point at this coil is a s-bar route the packets. So what is done yet? Routing is done. Giving their detection to the packet will walk audit suitable, and fragmentation is done and reassembling or packet explicit. We will discuss all these things are Fido. So now sinking with the example here, if we see here, so the delivery person who will be delivering the food to the customer. It uses GPS, Google map back this way. Responsible to bring the shortest paths visible bought. So who better map for whites are very short, shortest spot. And this is how it syncs with the real world, this network, real Leo, BEC, and sing with this needlework. Now are the three steps of which I have seen what, what all these are rounding fragmentation reassembly. So it does describe here indicate so logical addressing posts. So yeah, these are the virtual addresses. So that it will be a virtual addresses which will decide what how the packet bought destination would be there. I know I'm done or do you send a packet? That packet will be going through the network. So we're going to be now between the networks. So these are the watchin addresses, that is logical addressing which will take the packet to route through the network to reach that destination. So yeah, IPV4 odd IPV6 protocol is used, so does use to simply his other virtual addresses, which will decide what destination will be there so that the packet will route you wouldn't read today and we'll be using this protocol. And thus I can process second step in this Viterbi data encapsulation or our verbal encapsulate this data with their, with the source and destinations. So there will be addresses associated with this data source and destination because as I told you, it is used to route. It will give the path was to appoint what parts should be reported. And it will also see that it will be having a source and destination address also, so that the data will be reached through its final thoughts, source and destination. It will be sinking with her. And then after segmentation resembling so here, endocrine stage of entity. It will be first of all, isolated data spots, then it will be assembled it, and then we have to assemble it. So empathise very much notch. So it can happen that the one-day ties all these datas pleasant in non-contiguous locations in the memory. So what, what did we do? It will be fragmented. It will collect all these data from one computer's location electrode. And it will collect sizable Jiang saw what size it should be grounds for. Depending upon that, it will collect that data which is present in different, different memory location, and then the data will be transmitted. So this is about fragmentation. And the protocol which is used here is though, that are now being information protocol because yet pumping is done in the snow in this network layer as well as Open Shortest Path First, because it proposes that shortest path, this protocol is used here. Now I'm going to download their SDK and include. So this is what does this data in England, as we have seen, it is also goiters over the network. It is used to control the network card. It is used to manage the Mordor mood connection. Is that from the upper layer and that is the transport layer. That is one the negative locally or to use the same network, then it will manage it you have seen in the previous lecture. So what this data link layer do, it ensures that the data will be transmitted without any editor. It will do that part. And also we have seen, does the Italian clear answers talk to somebody who has we have seen advances talk logically control and also media access control. We have seen oneness and that logic control that we have seen in previous lecture that is used for multiplexing and addressing and media that is marked as used for hydro. It provides advice and direction. So these two layers, what David do, Sebelius, which they will also provide the success for transmission of the data. So all these things are associated with it. So he had it been, have this li and we'll have the Mac physical address, which will define the destination address where the packets three. So what does the endocrine system, the MAC address. We have seen this magnet is a physical action, physical address, which will help that person who reach to the destination. So this is very much important. And so UDP segment example is their destination, physical address, or the customer delivery person. Knowing I in order to help food estimate. So it said to seek physical destination, physical address of the customer. So now the protocol used here is Ethernet and point-to-point protocol. They're now going to the very last layer, that is the physical layer of 70 have seen network card or the metro cables. All these comes under this physical layer because it is linked with the hardware network part of it. So these are the components. So obese, the customer who's feeding comedy, comedy would place the order. And he said, We will consider to becoming another physically on the customer's reading, one of whom. So this comes on metaphysically agree through this course. I've been low if you share your reviews and ratings as it means a lot to me. And when influenced me to publish such more on-demand videos as per your requirement. I'm done for this lecture. Thank you, thanks a lot. In the next lecture we will be seeing windows rocket methods and enough socket method so as to bring the communication of the socket. Thank you friends.
7. Socket Session4 ServerClientMethodsWindows Part1: Hi, welcome to this new session, that is socket server client methods for being both. So in this session, given BC, the below topics that he owes, other topics which I had mentioned, we will be looking into the environmental setup at this January for both said about M client socket. So this is the same Goleman building Waterman Center required for both server as well as client socket. Then we will be seeing the adoptive topic that is, the median would be discussing Garmin efforts are the APIs that the January cohort server and client. So there are three methods that are to be API's retarded only for both hardware as well as client for the Windows operating system. So we will be seeing is three methods. You'll be seeing what is the purpose of these three methods and how they are used will be sinking in the chord. So this session is very much required prior to the socket programming process, but inclined for Windows, Windows operating system on IDE. So before executing the code, before running the code, we will be understanding the mappers, the functions which are present, and outlines socket so that you will be getting a better sense of what we are doing and it will make you understand in a easy manner. So these are the methods which are vividly discussing. These are the common methods required for both server and client. For Stephen, be looking into these three methods, then we will be seeing next. Decidable socket methods are APIs that will be specific only to the server. So setter methods which will be specific to the server that will be seen sinking with the code. And then we will be seeing the client socket methods that can be specific to decline. Again, thinking with the goal. So this is what we will be studying in this. So it is very much must in order to start the programming for settlement and light. So you should be knowing what all functions are used, what is the purpose of those functions? So it will make you understand in a manner. So let's begin. Here for us, you will be discussing the Arab discovered it in the topic word of course, topic which we will be discussing in Berlin Waterman setup. So prior to writing the code and executing the solver window socket programming, these are the little steps. So before writing the code for your socket, said look line, this is the generic method building ordinal setup required for wood's seven flight. So first of all, since we will be writing the program and executing on IDE, that discord block. So far is we have to create a project, but a chord block. So this case on the Windows operating system, we have to do the sector in this manner. We have to add that. We have to link to them in good socket library so that we can use the functions or methods which are present in this Mendoza conflict library. Since these, these will be using when socket 32 library functions. So before I start writing the program, which will be calling the methods as are the functions which are defined. In the library that, that is called as w that we have pulling this library, if you don't link this library, once you compile the code, it will compile because it will get there thereby. But, and you execute the code because you know that while executing the code, it will be linking to that. I really fine. So in that case, it will be finally the library. And since you have not linked to the library in the modern sector, then you will be linking letters. So don't worry about this. We will also see how it will only be in the next session when we start, I think the program, so this is for your understanding purpose. I have also mentioned in the presentation itself that what all things are done step-by-step so that you can live there and repurpose some video. And we can refer this presentation here itself. So first of all, we have to create an empty project and not woodblock. Then, since it'll be writing the program for the C plus plus, then we will be adding an MPC plus the source file to the project. So I will also show you in the next session and we write the program in the pore block itself. How to do just these are the steps which are made me no, no down off it. And we have to ensure built in water and then links to them and Socket Library, that is Ws to underscore particularly short-lived. So these are the steps for linking that also I have mentioned here. So we have to go to the project, we have to go to the middle option and then click on the link percentage settings so that our linkers link goes, I think, so that you can link any library to it and add the following and the linker options. So all these are the steps to add Susan's me or using really be using writing the program for the socket for the Windows operating system for cell hook line. Since we'll be using the methods as well as fungi are the functions which are defined in this library file, that is, this one, Ws to 32 dot. This library contains all the windows object method's functions defined. So therefore we have to link in this manner. You will be linking, might be giving these two lines that is minus W in particular and this one. So this is very much important, will be also seeing in the next session how to achieve, how to perform this step-by-step losses in order to link these libraries. Since this library itself will contain all the methods or functions which will be using for performing them in those socket programming. So this is debate of Northern men don't set up which is required for writing client program on the Windows operating system. Then I have mentioned very much important if you don't use libraries and you really get to avoid that. You have to do this billion more than one set of letters in killing that library file. Then you can begin the programming for the mini socket application for Windows operating system by this mentioning header file. So you have to mention them in socket DO2 header file that also explain you in the next session what all enterprise Arctic wire you have to manage. You'd have to include actually so that you can know golden functions. And when those socket. So these, so via, via the identity disbanding Waterman density for Windows for socket server programming. Now let see other topic of this session. So here we're going to be discussing the common methods which can be used for both socket settlement as well as client following those. So this is specific for a specific part of Windows operating system. This particular function is used that is common for server as well as client, that is Ws tech startup. And it is having two arguments. So you can see this forced argument as given in this man. And the second, I'm human doesn't address on this WSDL leaders. Foster boyd, What is the purpose of this WSS startup function? And it is required we have to, you have to use this function in Bork said, Venice client, supposed to boil by what is the purpose of this OWN a start-up. It is used to initialize the library. So since we have seen that the mental KC library that is sneaking in Berlin Waterman setup. So to initialize the library, this function is used. So what this function will do, west appointed to posts, argument register, present sensitive, and initialize them in soc library. So the cost of the program will really help us all Lindbergh wrote down one to use, which was this hybrid even socket that may be mentioned by this post arguments. So this make work and this band is, as you can see, Denon record two comma 0 specifies that the program wanted to use a version 2. Although library there is we have seen, so if we have given different version actually, so this going to defining their devotion actually budgeted program one do you like only so I have mentioned here itself the FED ME DO, which was of Vin socket, the program one. Oops. So here the main, what DO comma 0 means? It wanted to use the washroom 2.0. soda program when to use a version 2.0. or that mean Socket Library supposed to apply this function is used to initialize the library that has meant Socket Library. And the post argument will tell the program wants to use, which was one of them and socket. And what does this second argument telling about the forced upon this second argument which is that it is the address of WSB data. What does this WSB data structures? So 1D structure, like I had mentioned here. Suppose you put a second better meadow is appointing DO know WSSE data structure. So this structure in which the liability even tell the program built on negate the program about the critical information that the library, even Socket Library. There though. Program that how much number of sockets are required to be created. So that is a critical information which the library will pass through the program seeing what are, how many sockets, number of sockets you can create. So this structure will be filled actually before. So the structure will be quit before returning from this function. So I hope you understood the purpose. It is used to initialize them in soc libraries. So yeah, we have to mention the abortion which you want while they've been socket library. And this will provide, this will communicate the information, critical information from the library when socket library to the program, seeing how much number of sockets are required. So this is what the function is required and this is specified on need-to-know windows of what a Windows operating system on this function is required. You need to use this function for a board or server, as well as what lie in wait for the Linux operating system. I will be also mentioning what other things can be used for Windows and Linux so that you can start the programming with Linux also. So also a downpour you, since this session is explaining you about what all functions are present more and more admin setup is required to perform socket programming. Sort of alkaline water windows operating. Also. For the Linux operating system. Almost seem functions which you can use. You don't required Debian Linux operating system, the built environments, or WE simply you need to just install the compiler GCC and it might be already stored in your Linux operating system. You don't need to link these libraries. Also we have seen in Windows and the system that we need to link all of these libraries, Albia delink, only this library that is Louis Zoo, and an endless quarter D2 decidable socket library. Since we have to call the functions from this library. And so this function is defined. You should not get delinking Arezzo have to link this library, but in case of the Lena's Feistel foil and this library. So in case of d, industry dorm, wire dueling, this library that is no build environments set up like this. Nothing is required. Only you need to, you need to make sure that you are GCC compilers installed. That only is done for the windows. We have excluded this extra sector. We have to link this library in order to use this functions which are present in this library. So this is where the trends and Windows and Linux. So also in telling us we don't require this function, which is that this function is not present. So almost all the functions are similar to Linux and Windows are similar only the fuel methods which are not used in Linux and there are difference in only few methods. So a dysfunction, as I told you, is only specific for Windows operating system. This is not used for the Linux operating system. So a line by one, I will also differentiate within us so that you can start your program with Du Liniang soil so there is no much difference, unevenly or minimum difference is there. So that will be very much easy once you are capable of doing the program in this Windows operating system, it is very much as equal to win the Linux because wondering goes, these are the steps and board earliness. It is more easier than this. So you can understand, you will be invaluable for whom the programming. So we will also see in the next session. First of all, let me see the next session what role methods set up static wired one also the Linux operating system to go home the socket programming. So they did this session really tenable. What does metalloids and Berlin Waterman synaptic wife or Windows operating system. And in the next session I will discuss what methods and quarter million Waterman setup is required, what header file is required for the Linux? And then in the later session, consider differences between the socket programming for Windows and Linux waters have depth is required. What are linking libraries in windows we have to do and not we have to do for Linux and we're don't header files are required. And what difference is in methods or all the points you'll be discussing step-by-step. So let's see. So I hope see you understood, understood this focus on w And now to the next TO function, which is common to both server and client. It is socket function. So this socket function you have to create or sideways as well as wildlife. So we have seen in our earlier session on so that was our inclined board. Navier did require to create a socket actually, and it need mournful communicate between server and then the socket which we will be, we will be using, you'll be creating shouldn't have the same socket type as well as they should be having same ambulance domain. So these are basic things about the socket and discussed in earlier sessions. So I recommend that, I recommend you to go through this, screw through that session before coming to this. So it will also help you to understand what is, so what is the purpose of this socket? I stockholders soccer indices are published that is used to create a socket. So now while creating the socket, we have dimension. What is the socket type? So here you can see the second three arguments present. And that is if I underscored ins and song underscore cream and this is a group of oil. It is IP protocol and PCP. So hostile that ever via creating socket, we have to mention the socket. So this archetype can meet the streams type or it can be a panam page. So I will also mention on insertion basic socket that though, what types of sockets are available and Warhol address domino soul here, this socket types can meet unreliable type. That is the obvious team pay on unrealistic picograms of using the stream that is reliable. So most stronger tying this gene diapers news because it's very much reliable. And what all things were done. And as I mentioned in the previous session, please go to it. So this is the second argument topic. And lets see one by one or two or three arguments are. So, OK, so here this occupants is consisting of three arguments. The first argument EF underscored, that is the smart water this, so it is an Internet address family. So here we are using the IP version four. So there are two types. There is IP version four and IP version six. So since we are using IP version four, we have to write this internet address families ir, underscore RNA. If he would have use IP version six, nannies should meet IAA and the school and specific for that logistics via blue, right? So this is this metadata about the internet address families. So you have to give in this magnet itself. And the second argument that socket stream that as I mentioned you, that it is a streaming sockets. So this reliable socket. Then we have to mention the type of the socket, whether it is a big theme type on REP dissolve, datagram type, so sincere and using steam. So you have to mention you and Todd argument that is this one. It is, it is mentioning which protocol is used and for this orcas Gim me, have you have seen it used a communication protocol, RTCP. If this dipole, this socket was there, datagram, and this will be a UDP. But since we are using their type of socket, seems so it's communication protocol is TCP or oblique IP. So I mentioned in the earlier session or the socket V6. So please go through it for understanding what is illegal. So no editable redundant socket method will return though. Descrip goes or refresh referencing to the creator socket. So what this particular function admin ridden it Mildred ridden on descriptor to adopt new socket which is created. So by adding that descriptor which you'll be getting there. And you can use data descriptor and you can operate the perform different functions. So lets see one by one. Now, another common method which will be used for server as well as client is the clue socket. So here it is used by the name itself. You can understand any other set of a socket or it can decline since it is common for both seven and plenty of Lukoil dysfunction. So here we are calling for those service idea of looking at this, I was occupied. That is a descriptor. Any produce deadlines, soccer, then you have to give their descriptor of the socket. So year two for this, it is used to disconnect this rocket, and this is v. For the Windows Operating System, we have Golden Globe socket first of all, and then you have to do w. So what does this WSS cleanup? Because to deallocate the resources which are used by the Socket Library. So this soil are the details and how do you use it in this manner? So these are older, are the common methods that will be useful. Sidebar as client knowledge see specific methods which can be there while the server. And then we will be seeing the specific methods for the lines bothering those operating a system. So now our friends are going to be, now the specific methods which we'll be talking will be common to board or the Windows operating system, as well as whether the nurse operating system on these specific methods are seem. Though that is no difference in the functions for Windows operating system as men as one Linux operating system and you write socket program for sovereign claim. These are the common methods. It can be used what will adopt them. So only the difference I told you was in this function that is WAC started setup is used on Ebola and goes operating system. You have to require a, it's common for server and client Windows operating system, socket programming. And also one more thing. And I go disclose socket. So this is also one difference and windows operating system and solid. In case of Nino, so-and-so you will go out glucagon that loss. You will also disconnect the socket, but not calling this function will be on IQ loss functions are to be met and be mentioning that in the next session, what methods is used? So only that Louis XVI use, you don't need to clean up all the different ways there to closing that to disconnect the socket. So this is only the difference in between the windows operating system and done Linux operating system or socket that look lines. So all the resting stack now we will be discussing here, that'll be Coleman, Do the Windows operating system, Linux operating system.
8. Socket Session5 ServerClientMethodsLinux: Hi, welcome to this new session, that is sockets advert
client methods. Minutes prior to the session, he had seen the lecture for socket server client
methods for Windows. I hope so you've
gone through it. So it will be good enough
if you've walked through that session because almost same concepts
is explained here. But I have a differentiated
for the Linux. What specific things
I used for the Linux, what all complete setup is required you'll be
discussing in this session. It is not more than that. It's not much difference. In the Linux and
Windows socket server that only few method
defenses rest all are, them are same as come back
to the back of them windows. So I hope you've gone
through the earlier session. So to understand more quickly on this session, I'll cover it. Little colliculi because
almost the common things which are here present, Linux and Windows mu will be moving weekly and rest of the things which are
specific for orderliness, I will give him on that. So that is going to be on
so far you to sink more easily instead of going through
what session repeatedly. So let's see here, what is the sockets have
online methods for the Linux? What all things are,
they're not required. Let's see, step-by-step. Don't worry, you will
understand each and everything. We will be moving step-by-step. The topics which I'll
be covering here, it will be discussing
the common methods are the APIs which I didn't record board server
as well as clients. So these are the two methods. So here in the first topic
we will be seeing what all common methods of
functions are there, which for the
sidebar then client, and that is used for the Linux. So these are the methods
which are common. That is, there are two methods. Socket method is dead and the another method
is the close method. So in case of Windows,
we have seen, in that case one extra method was there that is WSS startup, I told you that is used
to initialize them in socket library and we have
to link onto that library. But in case of Linux, that method is not
at all present. That was an extra thing
regarding the windows. But in A's ugliness
that is not there. So we'd also need to link
any library, meant socket. We do need to link any library
in case of the linear, it's just you have to install. Gcc compiler is installed, and we are able to
start the programming. These are the methods which are common for
server and client. That is, both of
them will be used now let's see what it is. Now also the other topics which will be discussed
will be the side where specific methods and we will be sinking
with the courts. And we see all the methods, whether side-by-side, which is specific to the server itself. And we'll be seeing all the methods for the client which is specific to the client itself. So also these to all the methods which
we'll be discussing, model and specific and
the client specific. The same methods
which are used for Windows also all
these methods are used also for moving those. So almost everything is
same, just the differences. That year the WSS Startup
function is not using Linux, as well as the SOC close method
which will be seen here. The syntax operate is different. Everything is similar to that of the windows as well
as for the linen. So this function specific to
the server will be also same for the Windows and Linux and deadlines specific
methods will be same. So let us see the
things then discussing the same common
methods here govern methods used for server
as well as claim, this is very much required. The important node which I told you that in Lena's there is no WSS star dot function used that has window
have this function. You have seen that
the common methods which we have discussed
in earlier session, we have seen that there are
three methods out of it. One knows WSS startup
that was used to initialize the library, that is the wind socket library,
and you have to link it. So here in this Linux, this function is
not at all present, so do you don't need to
worry about linking also, there is no set up
required for that. So that only her maiden
who download it. Then coming to the
genomic methods which are used for server as well as client in case of Linux. So socket is used. So this is the same way you
are doing for Windows also, you have to create the socket. You have to pass
arguments in it. This first argument is
the address family. Here. It can be for IPv4, IPV6 when we give EF and the school I in
it, that means it is fun. I think he would
have mentioned six, then it knows what IPV6, this is this indented
and his family give as it is, as
I have given here. Second argument, you have to
pass the type of the socket. So this I had discussed in those topic Basics lecture prior to this session and said that though there are
two types of ducts, socket types, that
is stream socket and datagram sockets and stream
is a reliable one manifesto. I'm datagram is not
reliable and he had seen what all
features are there for the reliable one
and what unreliable, we're mostly using
their level socket most of their time because it provides error
correction everything. So all the things
that you can go to the first session,
so it could be six. And the third thing
you have to mention the communication protocol. So here since this gene, so I'll confuse this
communication protocol is TCP, we're mentioning here PCP, if it was though datagram and it uses different
communication protocol, it is new that also
I have discussed in the onions session on the
no damage I just mentioned. Then there are three functions the same way which I
mentioned for the windows also the same or
ignore it goes then this particular
socket method will return a descriptor
pseudo socket. Wherever you are creating the socket for the course
or where our product line, it will return a descriptor
to the socket for that dark line depending
upon where you're using it. Then the next thing is
that loads function. So here again, this
close function is we are using in case
of windows closed socket. So there is different
representation. You disconnecting the socket
as compared to the leader. So Nina's me, I use includes and we're maintaining
their descriptor. You if it is sidebars soccer, react losing it,
then you have to mention that it's
scripted of service. Okay? Yeah, I mentioned enclosing the socket product line than you are to
descriptor of decline. Then the next thing now you'll be seeing those
hardware specific methods. This is common for
Linux and for Windows. So all these things that will
be repetitive if prior to this session you
have gone through this session, that
is socket said, Well client quad windows,
if you have gone, then you will find this
thing almost same. This will be specific
to the sidebar. So we have already seen that the sidebar need to bind to
particular IP address as well as though port number associated whenever any communication
needs to be happening. First of all, we have
to show that server is running post so
that it can exist. It's capable of receiving any
connections from the client whenever that is an
Ignite this client, how it will understand the
identity of the server. So that is the reason
the Salvo should be binding to a particular IP
address and port number. By the name itself you can understand mine means
it is binding to something inside
of whether it is binding to the particular
IP address and port number. So this whole, what I
have told you is written, this is how you call
the bind function. You write the pulse
argument as a descriptor. Then you re the second
is a pointer to the structure and then the
size of the structure. So this descriptor is
a descriptive which you reach the socket when
you call the socket method, it returns the descriptor to the sidebar socket so that
you have dimension here since via a sends me out
using their descriptor of that socket only we need to bind sediments, okay,
We need to mine. And the second we are giving
the structure of the socket. So weiter structure is required. It is required so that you can fill the details of
the address where this advice should
buy into end up with a number and other things
like address family. I also explain you this address
we're filling it is if we have given in server an EdD at underscored and
install a new session. I'll explain you want to sort importance of it is
very much important. The code number, it
should be greater than 10 to four because it is
used when 0 to four. So it should be
greater than 0 for any of them used in
particular number. It is explained by three-fifths. We'll just go
through and see what is the limitation
of it is 65535. And then this is the number
one, whatever you mentioned, the port number on the
server you have to mean mentioned the same
window. Client outsource. This is a port number on
which the server is buying. Do. I have explained now when we have done
error checking here, you can report it later. So I have explained you
all these parameters. This is just a No, don't put it. Seeing the next function are decided by that is
listened function. This is common to both
Windows and Linux, specific to that server. Socket. Socket. For the lesson, once it binds to IP address
and port number, it should listen on that. To listen Dan, new
connection from the client. Also, one thing I have
added here just now because it's some type
of mistake was dead. Also, the same thing actually
just listen function. I have missed that in
case of the windows also what the server
socket methods. So here the extra
parameters that, that is in bendy are
called Allison punch. But in the programming I have written in the same
manner we have done, which I'll explain you,
which will be executing it. I've executed in this manner. It said, passing the two are
humans that is required. So just mentioning in this
presentation, I missed it. We talk about the lesson
function when extra pedometer, which I have edited
as the backbone. This backlog of which is
the second argument here. What it is, why it is
required most of all u and v mentioning the
sidewalk socket descriptor. In the second backlog
means it says how much connection request of the client should
be in the queue. For example, if you give here. So that means you
are saying post-talk on this socket is capable of receiving either board and actions of economic decline. But that will be in the queue because since the Bazin
One is in the process, if there are multiple lines, then magnet and actions will be in bending connection request. So those will be waiting
actually for an oppressed in one who complete runs the
present mine is completed, then the side value
will be listening to those of the connections
one-by-one at a time. One will be processed, but other will be in the ICU. So how many number of connection of the client
you want to keep in Q, you can mention in
this second argument. So this is all sources
seem in case of the Windows operating system. So I have explained
the lesson function, but I have missed giving
the second argument and that just consider the same
thing that's in Texas, same since I just see him
for Windows and Linux. So the second argument will be added rest,
everything is saved. Just I missed this one. Now, this is how you will be listening for other new
connection requests, for their connection
requests from deadline depo dysfunction. Then you are calling
the exit function. And that's I wrote
the exit function wherein you will give the
descriptor here on the server. And then you will mention the
pointer to the structure. And then a year during different
things which are there, that is client a DDL,
which you will get. So here, first of all, in case of the exit function, this structure which you will be giving us all what it will
return this exit function, it will return our descriptor
of the new socket. So all you got to socket descriptor post
socket descriptor. You glide menu called
the socket function. Here. When you follow the
socket function, you bought one descriptor.
So there it is. It is used to receive
any new connections. For the connection
purpose it is used, that is this sort
descriptor which you get actually when you call the exit function
and this address. This is Doug descriptor powder. It is named as glenoid
socket because you'll get a descriptor for the new
socket descriptor or decline. So here with this script, you can communicate with
that line as well as you can send the data to decline or do you can receive
the data from nine. So deco photographers
could have Bazaar used as do not
block anything once that socket descriptor
can be used for connecting the
client requests and ISACA descriptives get engaging in sending and
receiving the data. So there are two descriptors. And this is how destructive the judgment explain you what, how to fill this structure, this structure you have to do. You have to mention the details
of the structure itself. The next thing between
seeing is that a C function. So also one thing while the server socket you can
call the receive function. You can call the same function. So anything you can call
depending upon the requirement. I have a nice look
into this index. But this isn't used to
receive the message from the client to see if they're
the adapter on that line. And here you have to mention
though socket actually. So here since we cannot
create the socket, actually we got this
descriptor when we call it, exhibits are at the
descriptor itself. We need to receive that. Whatever we receive from client will be collected
here before you can print this before it
is industry in character. So this is what the in case of the set of functions which
are specific to server. And these are the same for them in those and as well
as for the Linux. Now let's see the client methods which are a specific deadline. So reclining to just connect it same manner which I've explained you in the earlier
session for Windows. It is used to communicate
on the network. It is must do connect
to the server. Here we have to mention
this address structure. Also one thing I'm going very
fast in this session that is for the socket sidebar
client methods for the Linux, because in the previous
session that was sockets advert client methods
for the Windows. I've explained you everything
for the Linux also, the same thing just, there is a beauty Prince
which I mentioned you and your itself
rest dysfunctions, which I'm talking about. Almost everything is same. So there is a reason I'm just going really passwords very, it's recommended
that you bought with Danio session to
understand it more better. But I'm covering
each and everything. I'm not missing anything. So I don't want you
to go repeatedly. That is a reason gambling
past here to connect. **** line is only
supposed to connect. So this is the thing we
inclined to give their debt. So this is dimension though, IP address of the
local host machine. So in our case, E and B having the socket communication
within the same host machine. So it's even if you can, you can have socket
communication within the same host machine or
within different machines. So in that case, whenever you are having
a socket communication, you once I read inclined to
run in the same machine, same laptop seemed like stop. Then in that case the IPS, it should client
should connect to the salvage of give the IP address on the server where this ivories by m2 so that you can
simply mention the idea of the local IP address
because since we are running server client
on the same host machine. So in this manner, you have to, you have to mention here the
IBM Internet and his family. And the port number you
have to mention me was we had binds to
this port number, so I'll give the same on
the client side also, since client will be connecting
to the same port number, then we call the
connect function in pasta's descriptor of the socket which we got by creating it. Then this is just structured
between repealing with this, I'd be at this end, port number and the size of the structure. This is the, this is an old
Donato about table are the, another function is sensor ones. It's the client, that's
the connection by simply calling the connect
function in this manner, it is simply then it can
send and receive the data. So this is a syntax was
and you can also receive their quality seed
function from here. Sending it, we are sending
some character string, same thing, learning socket
programming in depth. We're passing the
socket descriptor data, sending this character
string which we have failed with data Buddha side of it. And then also from the client, that is from here itself, this data will be sent to the server in the
size of this thing. So this is what we
will be sending compliant to several friends. I am done with this said
Brookline methods for Linux. So you can understand
to summarize in short, you understood what
all the princes, their poster for a
dipole in Linux, there is no setup or linking the wind socket
library since we're not using those functions. In case of Nina's there is
no WSS Startup function. Therefore, this thing
is not dysfunction is not president case of Linux. Then rest other things like socket creation is similar
to that of the windows also. And the closing of the socket, we have to disconnect in
the case of Windows also, what does index foreclosing is determined in
case of Windows we call glue socket and
there are different, we do the cleanup also. But in case of the Linux, simply recall that
Lewis function to disconnect the socket. Then these are the
specific methods which are used for the server. Those methods that
are binding or the sidewalk that we
will be listening then accepting all those
things which are that will be common for Windows operating system as
well as for the linears, for the Lynas who answered the same and for the
windows on the scene. These are the things
which are there. In case of the client-side, also the client's specific
methods which will be there, that will be also common for Linux as well as
whatever window. So you have to connect
from the client. We have to send and
receive their function. Send and receive the data. So this is what we have gone through now in this
session I'm going to explain you the difference
between sockets set of applying for
Linux and Windows. So that I will explain you. This is all many things,
so they'll be there, which will be common
till now we have studied that is the winning
Waterman set up on Windows, just mentioning it to
link the library and then inconsiderate Linux
to just install GCC seemed to make
sure this is evoking. Then I'll explain you
what all header files are required for Windows, what own header files are
required for the Linux? Then what extra code is required for Windows and what
common methods are there? What I type checking, how you will report
an error in Windows, how you report in Linux. Dead lecture. We will be seen once you go
through this session, then later on we will be
starting the programming. Those middle we've
seen you'll be learning it and
also in wheezing. One important thing that is HTTP server client communication will be running if
you didn't see, seeing how the browser
talks with Apache server, how the communication
takes place whenever you open any site, whenever you want to open any Beijing Jenny on the browsers browser
is sending a request, how it will be connected
to Apache server, and how the data will be filled, how the page will be filled
with that, with that data, the page will be
loaded so that we will be seen using the socket, be using the HTTP
server communication that is very much important. So this is how we will be
proceeding step-by-step. Thank you. Thanks a lot.
9. Socket Session6 Difference ServerClientMethods ForWindows Linux: Welcome to this new
session that is difference between Windows and the
Nina's socket programming. We have already seen in
the previous session the windows socket methods as well as billionaire
socket methods. And I hope so you have gone
through those sessions. They will be very much helpful to under
spirit this session. That will be this
will be giving you the difference between the
windows as well as Nina's. But some adults here. Let's begin. Topics. We'll be covering the
defense in building water Admin setup to perform the socket programming
in Windows and Linux, we will be discussing about it. The next thing we
will be discussing what all header
files are required for socket programming in Windows and as well
as for the Linux. These are, these header files will be different
for both of them. Then we will be seeing the
defense and few methods. That is a functions for the socket programming
in Windows and Linux. Bob. So in this third one, you might be a metal almost everything because we have seen in the
previous session itself by making you understand socket programming for
Windows as well as Linux. I had told you what functions are used in Linux and Windows. Almost seminars are almost
all methods I use red cell, onsite depo windows and some slight difference in one of the function
and the rest. All of the things I've seen decided the setup. So let's see. The fourth, I will be
discussing the topic that is different scenario
Reporting between the windows as well as Linux. So let's start now the first very posting
that is the setup, the prince and the bill setup
or both of them, false. We will be seeing
the bin setup for the windows to perform the socket programming.
So this is B. This will be kind of
repetitive because we have seen in earlier
session on source, the Windows operating system to perform socket programming, we need to link to
the library that is ws underscore 32 dot lib. Because we'll be
using the functions. Functions are defined in these libraries for the
window, window socket. And therefore we have to link this library because
execution time, if you don't link this
library later on when we execute the program, then it will give us
the linking later. It will not find the library
since we have not linked it. So this is very much important
and the steps to link it, I have mentioned here the same thing, project build options. Then we have to click on the link or setting
tabs and these things, these are the steps that
you have to navigate. And then you have to
add these libraries. We will also be writing the programmer and show you
manually also how to do it, go through it on the
idea and explain you. This is very much important. The setup is really important. Otherwise you'll get a
linking at execution time. Now you have dimension, the header pilot case on the
window socket programming. Now, these are the
building Waterman setup, the elementary unit
if I later on. Then next, the building
Waterman setup for the Linuxes, you need to just simply ensure that your GCC compiler
is installed or not because it is
news to compile the code that are
different though ideal. And so if you want to go
through UI user interface, you can not do the command line. You can install particular ID, that case, and you can
create a project actually. And you can send leak or programming code and random or random socket
programming code. You don't need to
link the library. If you are using a
command line drawing, make sure that your GCC is, this is a compiler
is installed or not. It will be by default installed
on images and shorter. No linking libraries
will be required in case of the Linux ones. And we have to mention
some header files for the Linux also to do the socket
programming that we will discuss later in later slides. Now this is, this whole setup is enough to start the
programming in Linux. So this is what
evidence actually in Windows and the liberals. And the next difference
for the header pricing between what the
header file should be included or Windows to perform the socket programming
and for the linear zone. So this is in files which
you need to include my Windows operating
system to perform the socket programming.
You need to. I mentioned this stdio.h iodo, THE simply input-output to simply display the message
on the console or to simply give the input
from the console. This is what though. These are the credit
files which you need to give in case of Windows. Then the wind sock dot edge, this is specific to them when socket functions which will be declared in this header file. So you have to mention
this header pipe. Then you have to mention
STD lived on the edge. These are the three header
files which you need to give performing socket
programming in riddles. Then deadliness, you have to mention all
these header files. That is stdio.h
DIN socket dotage, I dotage, std lib,
string dot edge. And then you Anna,
Anna, UNI stdio.h. So all these header files. So you have to give, in case of the Linux operating system and you are performing the
socket programming. These are the differences
between them. The next topic actually
which we'll be discussing, what all different methods are there between the
different for Windows and orderliness when we saw a white socket
programming so far, windows, as I told you, this is the extra
function which we use. This is very much required for the Windows
operating system. It is used to initialize. You all have been socket
library though it will tell the network the program want you digital version of the library the program
wants you to use. So this will give
you the version two dogs 0 on the
wind socket library. It will, the program
will indicate this version you need to use
for this Mintaka library. And this function is used to
initialize socket library. And the second data structure
pointed to the structure. So the structure would have been socket library will provide the communication
critical information while communicating the program, seeing about how much number of sockets and allow
it to be created. So all these things out
there in case of New, in case of Windows operating
system, not in Linux. So this is an extra
function which is that in the Windows
and you don't know, you don't need to use a nominal. So this is a difference
in one of the function. This method dispatch
them individually, IX being new version, the course better read that as the visualization on libraries. Second, when I give you
the critical information how much on this
sockets can be created, there'll be sent from the
library to the program. This I had mentioned.
Yeah. Then Nina says I told you there is
no stock or function, no initialization
or cousin Nina. Now, another thing is that
in case of the windows, these are functions which are used to disconnect
the socket. We have to call it
close socket function. You have to cause this
socket descriptor. That is what I was
hoping that because I said about our
client had two fathers scripted offer depending
upon your requirement and WAS a cleanup function should also be called in
case of Windows. So what is this WSCC cleanup? It is used to deallocate data sources that is
used by the Beanstalk. This is definitely in
and it will return 0 and success and non-zero
number on failure. So I hope you understood this. These are the, these are
the methods which are used in case of Windows to
disconnect that socket, no functions you need to call. And there's a purpose
I've explained you up for the WAC cleaner. Then in case of Linux, in order to
disconnect the socket simply you have to
call the close. Then you have to pass
this descriptive. If it is satisfied, then
it will be the script up. If it is a Linux, if it is client, then it
will be applying. Good to go. This is simply closed. There is no cleanup and all. Then another difference and other topic actually
further defenses, defense and edit reporting
between Windows and Linux. So let's see for Windows, how do they vote in error? This is the function
edit response. The message will
be getting here. Then you would simply put this message and this message
and get it collected here. And this is a
function that is WL, I say get lost error. In this manner, you have
to report an error. So what does this
WSL getClass error? Now let's see details about all these things
now in window uses its own error message
facility yes to indicate that what went wrong
with the socket call, this function may return an integer representing
the last area there have a good decade by the socket
call field disability. Give you what my, what is the reason
of the socket video? It will return an integer. Now this has Windows version
ICD-10 of the edit responses uses duck, the last error. So this is all the
description about it. In case of Windows, we need to report an
error in this manner. Now let's see for the
linear Sweeney nuts are getting the same function, but this time that
it didn't call, we will do even call. This WAS a getClass
and of equal sum. If didn't function, that is B editor and
the editor message Yoda was SP edit to report
the system error messages. This is a difference. Now, all these things
are required actually. So this is, these
are the differences between Windows and Linux
socket programming. So you can see not much
differences dead or functions. If you talk in terms of the
functions only in Windows, you have to add an extra function,
OWASA Startup function. And also one other thing regarding the function is that the loss function is different. Syntaxes, different
model, Windows and Linux rest all
the things that is specific to the server
in specific deadline the functions are same so we don't we have
not talked them. I'm just dabbing setup is
different in case of Megiddo. So you have to add
these libraries, as I mentioned in
this step here. In case of Linux, linking
setup is required. And on Nipah Linux, we have to make two other
if your compiler is installed and the edit, the header files
which I mentioned, these are the
different enterprise for Windows and for orderliness. And the last thing about
the rape error reporting, this is the different discourse, different function in Windows. And in case of the Linux, it will call the different
function that is better. This is what, this is all. You have to keep into account. Both bombing the
socket programming for Windows and Linux. So don't worry, friends
now in the next session, even be seen socket sideward
client communication. It will be writing the
set of vertical board for the Windows
socket programming. And we'll be writing the client
code for the programming. For the client code for
the windows will be and then we'll be doing
the communication. I will tell you again, understand that there is many minimum difference
between Windows and Linux. So once you know the coding of the window for the socket
programming while you are, it is just one big
go actually, dude, to write a program
for orderliness, you don't need to
worry actually, it is just to copy paste actually gets off Nina's
because in Linux, it is very much a z than that of the windows are because some of the functions are not used. Also rest just the
defenses in there. The close function you have
to call indifferent minute as everything is same and there is no set up required
for the Linux. If you know the programming for socket programming or
decided what as well as client for Windows you
will be if it'd be very much Z redo the socket
programming for Linux. So this is how we will
be proceeding trends. Thank you. Thanks a lot.
10. Socket Session7 ProgramExecution ServerClientCommunication Windows C++ Part1: Hi, welcome to this new
session that is said about applying socket programming for Windows in code block
with its execution. So here we will be writing the code for the server socket programming
we will be doing, will be doing the client
socket programming, will be running it
for the windows, will be executing it
on the code block. And we will be seeing how would this socket set of applying
a minutes with each other. This session? I hope so You have
already visited the, all the previous session
in segments rice because we have covered
the different methods, different functions, the socket server
as well as swaddle, socket client or Windows, as well as we have also
sync with the code. What instructions are used, what all different
functions or use, what is its purpose? And how to for the server side, what all functions as opposed to be colon for client side, what functions need to be? Saw? All those things we have seen, we have also seen the
building water admin setup, which is required for Windows socket programming
to take place. If not, then please
visit those sessions. We will be starting coding for the sidewalk line
socket programming. It will be very much physical. You still, I will be
explaining since we'll be creating a new project in order to write the code
for the server, the client socket
programming for Windows. And we'll be doing the whole
complete the list myset up, seeing what all things
we have to link. What are libraries
are required to link? So you will still be getting bands we go through
this session. Let's start. So to just revise, we have seen several
socket methods. What are the servers are
good methods we have seen. First of all, there is, you have to initialize WAC. This is required on
Windows for Linux, we don't need to initialize WSL. So we have seen what is
the purpose or topic. It is used to initialize
them and Socket Library. And we have seen how the
program will get the abortion. It one, but I've
been socket library. So the posts are human. We have seen, you have seen
what is the second argument. Ended up APA Socrates to initialize dove and
Socket Library. Then second function we have
seen to create a socket, then it will return or
descriptor of the socket. So we have seen that
at creating a socket, we have to give the
socket type and it is regulated as
a stream socket. It is reliable
socket or whether it is datagram socket at
some level, socket. And it's about as
we have to give the communication protocol. Since we know that stream
socket is using TCP, datagram is using UDP. We can create this socket AND gates on the server methods we have C and then we get
this socket descriptor. Then on the server
side we need to bind this socket to diabetes and
port number we have seen. Then we have listened
on that socket. So we have seen no van, we listen on that socket. We will be passing the
socket descriptor, as well as you'd be mentioning
in the second argument, how many number of those
socket connection from the client should be in the pending queue, in
the waiting queue. And then we have a
boulder exit function to accept the connection
from the client. And then once the
connection is established, so when we call this
exit manage function, it will return another
new file descriptor. And this file descriptor, we can perform send and receive began for home send and
receive data with that client. This socket descriptor,
which it was. So return from this
create function. This, we will keep it engaging
to accept the connection. And another socket, new
socket descriptor W, keep it for reading and
writing for communication with that popped up 9% data as
well as to receive the data. So this is how ended disconnect
function we have seen to disconnect the socket in case of the server socket methods. Then we have seen the next thing that is the
client socket methods. I didn't need to
initialize the essay. This is also specific
for Windows only. Initialize the
wind sock library. Then we're created the
socket on the clients I underlined there is no much code if you functions are used. So we have to
initialize the US it to initialize the wind sock
libraries so that we can use it. Then we have to
create the socket for that client and server are
different applications, each of them to have this
socket creation on them. And also we have to mention
the same socket type as well as the target
communication protocol should be same either side, but as well as
sparklines so that they can communicate
with each other. Then we will call
the connect function so that the client can send a connection
request to the server. And then once the connection, once this connection is
accepted from the server, then send and receive stats
from the client itself. Then disconnect function,
don't disconnect the socket. So all these methods
we have seen now starting now let's walk
through the server, client server programming
in code block of Windows. Let's create a new project that you need to install
the woodblock IDE. And it is really availabilities
and open source. So you don't need
to buy a license. If you've seen, if
you install this ID, you can write the
program with me and executed and see how the
communication takes place. I've already installed it. I'll open the whole block ID. I'll create a new project. So first we will be creating a new project
for the silver. Then we'll create a new
project for that line. Once the code block
is installed, just double-click on it. You will see this page. Now, let's create a new
project by clicking on File. Select new, and then
select project, and then select and
soil application. Then click on Next. Then since we are
writing the program in C plus plus it's already selected, click on Next and then
write the project name. So this is sort of a socket. Windows should be
very sensible name as well as short name so that you can understand what you
are doing in the program. This is a folder name that you
want to dump this project. Then click on Next and just create a default Hello
World program for you yet. Now we have to replace
it with the server code. I've already written the code. I'll copy here. I
don't want to waste time and writing single,
single instructions. You have already seen in an earlier session what all
instructions will be using. I will also explain
you line-by-line the instructions on
game program itself. And then we will
be executing it. While you do it. Again. Writing the whole code, let's dump the code which
I've already written. The code which I've already
written I've just downloaded. I have just increases, increase that
exercise so that you can see what coding
we are doing. To increase that excites. Now let's start by understanding
this program one-by-one, line-by-line on the server. So it is using the same malfunctions which we have already seen till now. Now, the execution of your program starts
from the very first, that is the main function. I hope so you might be knowing
what is the main function. Main function is the function better it whenever
you compile the code, whenever you execute it, the execution of your program will always start from
this main function. Whatever lines of code you will be giving in
this main function, nine by nine executed. And it is an entry point
to start an execution of the program so that control costs comes in this
main function and motor, whatever lines you
have written here that will be executed
line-by-line. Now, let us see for the
server code what we have written for
socket programming. We have declared, we have
seen this as WIC data. We have seen what it is. We have, we have initialized, we have created, created the
variable on this data type, that is WSL data. We have seen that in case on
the windows, you have foo. Initialize the wind
sock library for that, we will be using. You'll be calling
startup function. This startup function is having two arguments
out of which the second argument is the pointer to the
structure WSL data. So widest structured
as required. We have seen that
we need that DO. Those are library events often. It will communicate
with the program, giving dog information
about critical information, that is, how much number
of sockets can be created. This structure will be filled. And so since we will be
using it, therefore, we have to create a variable offered in this
manner, WAC data. Then we are creating the
object of this socket. We are having two
objects on this socket. We know that the socket descriptor will be receiving when we call the
socket function here. And I've got a socket
descriptor me to be deceiving when we call
the except function. So exit function onto their than one mode socket descriptor. We have seen that
there is a reason yet. Creating the object
of this socket, we are creating new objects by the name server socket
and by the name I'm sock. Then the next part is SOP
ADD or underscore ions. So we are painting
again to object because in V&V called
a socket function. When we will call
the bind function, you have fulfilled
all structured with IP address where those server will be hustling and
with the port number. So that is the reason this
structure will be required. And that will be at
creating the object of it. And then again, my most
structured is required. It is required whenever you
call the exit function. Here we have to mention this. It seems here. That is the reason this
is required and you are creating on deck
offered in this manner. Now, the very first function
that will be called UFC, he have to initialize
them in salt library. So therefore we will be calling this WSS Startup function. And you'll be passing
two arguments. The first argument,
which will be better, it will tell the
program wants to use the version of bug
and socket libraries. So since the program
wants to use a version 2 before the first argument
is given in this manner, make what in bracket
two comma 0, that means the
program one to use. When Socket Library 2. The second one that is a
pointer to this structure, this structure of witches, that the data will
be here though. Socket library
with elder program or how many number of
sockets it can be created. So this will get filled before the WSIS Startup function
comes to an end. This is how this will be passed as an EMT
and it will get filled. Haven't talked library and this information will be filled. How many number of
sockets will be, again, be created? Exit
prior information. This is how we are calling this function for the window socket
programming and server site. Then the next thing,
since I don't, you know, part of the rule
is to create a socket. Now we'll create a socket. So by creating the socket, we have to mention we have
the victory things that is posting will be
the address family. So we will be using IPV4 and deployability
in this manner. Second one minus the
socket, socket tight. So we want this stream
socket to be created that is reliable and carbon beta
communication protocols. So we are giving it as zeros, so did before it can be 0. For this stream it uses
TCP, you can use Xero. Another. Once we call the
socket function, it will return the
descriptor of the socket. Now, this descriptor
will be using for different functions ahead. That is for the bind function or the listener function as well
as for the exit function. Now, you can see what
we're doing here. We are filling this structure. So what is this set of ADD? I said earlier it is of
the type socket ADD. As we have seen that when
we call this is required, this whole code is required
in the bind function. Since in bind function, we will move on the
socket to be binding. Particular port number
and IP address. Port number and IP
address should be given in the structure. That structure is server
ADD or that is other types, sock ADD or underscore iron
via filling one-by-one. I told you this address, which we are giving for a
server to listen to bind to this address is what I have explained you in detail
in earlier session. Let me give IN, ADD
and underscore. It means that you want sidebar to all the IP
addresses for victim, different network
interfaces on it. Though users using land
to fetch the Internet, then the IP address of that land will decide where it can bind. And if the user is using Wi-Fi, that is different
network interfaces are having different
IP address dense over that IP address on
the same host machine. Then the second argument we're
mentioning the VM image. I mentioned the family. So when you give
them this manifold, IPV4, it will be in this manner. Then we are giving the port number quantity to the salvage of give me four times five. We can give any port
number greater than 1024, less than six by 535, because one till
1024 it is used. And though after 10 go for, you can give any of
the port number. So whatever port number you will always remember
the client side. You have to give the same
port number because clients will connect to the
same port number where the sidebar is mine
to all the structure. Once it is filled, then you will call the bind
function again. You will pass the
first argument as the SOC is what it is a
descriptor actually which you, which is which it was written when you call
the socket function. This is a socket descriptor. Here we are passing the posts
and human second argument is the structure that you may have felt
we're passing here. And then third one
is the size of this. Info. Now this, in this manner, by buying function
now the sidebar is binding to the port
number and IP address. Now what listeners doing
in case of the lesson, the lesson function, you are
passing the first argument as again the descriptor
of the socket. And the second argument, number, client connection, which
you want to keep in q, since we don't want if
you don't want any, any client connection
to keep in q, then we can simply
write 0 or we can write one if you want one connection, it will be in q auto
connection and cube. This is how it works. Then this lesson means
it is listening to, listening to the Connect
line connection. That's it. Then after that we
will be calling the exit function to exit the
connection from the plant. This mean bars,
again this socket descriptor that got returned
from the socket function. Second, we will pass
this struck dose, so destructed as an empty, it will get filled actually. Once we go on called
exit function. Here, all the client related
details will be filled out. All the information
related to that line. What is the IP
address, what is it, what port number it has mapped to and all
the details it will be filled actually when we call the exit function and
the size of this. So therefore we are
simply passing as it is. And then it is running, then you find new
socket descriptor. So this descriptor as
well as this descriptive, both of them are different. I told you yet is
different because this descriptor can be used to accept other connection
requests from that line. We don't want to get
anything blocked. So this Socrates engaged in, in listening and accepting
the connection. In that case. We also want simultaneously
read and write operation. Once it is, it is accepting one connection
from the client. We want read and write to be hunting and we don't
want it to be, but therefore, another load, the script of another socket or descriptive will be middle
GET and we'll keep that, engage in reading, writing
this one and this one. What accepting another
client connection. I hope you understood this and this and
this will get done. It once said about accepts that connection
from the client and it is capable to receive the
message from the client. So your descriptor itself, we'll mention here, if
this is successful, then only we can receive here. So therefore, if
condition is mentioned and this V right client
is going to get, you mentioned this
socket descriptive. Since we need to receive
on this socket itself, then whatever the client has said will be
collected on this buffer. And then we'll
display this message. Then memset is buffered to 0. And then this is how after everything is that
I'm losing the socket. So it depends upon your usage. You get on so-called
the same function here. If you want some
motor information to be passed from the server, then you can call
the same function. And if you want
repetitive connection, you can put up a loop here also. And you can write
the condition that if somebody walking
condition that it user give this and come out of the loop
and don't know Nieto beyond want any communication
depending upon the usage. Again, modify the program. This is a simple program and I'm receiving the message
from the plant decor. I'm calling this receive
function even I can call it a sine function if I
wanted to send any data. It is same. So safety
function and will be calling from that line so
clients can send a message. Even in the clients
that we call, we can call the
receive function, yet we will be here. I am showing you about receiving the message from
the client site. Client side will be
sending that message. Now, we are closing the
socket in this manner. This is how this happens. I hope you understood each and every line of code
and this will, we will find it more
than Z because we have done all the prerequisites before starting the program. We have seen all the
functions in detail. Sinking with the code. I request you to go
through it if you have not gone because I have repeated
all the things again here, but in more detail of
explaining that session itself didn't make
you to understand. Now, let's build up.
11. Socket Session7 ProgramExecution ServerClientCommunication Windows C++ Part2: Before that, you want
to set the lungs. So I've already said
the log to secondly, for increasing the size, I have just still. If you want to belong
here on the console, ward setting is required. Click on New, and then you
need to check on this locks. Once you check on this locks, then you will see this beloved screen I've already checked, so I'm getting this
will lock screen now I am how to build a
program. Click on. Let me clean it because I've already tried it just a second. Okay, now click on Build
and then compile that file. So here you can see there
are no arrows In TO, in the server side.
Now let us link. Now I wanted to show you
one important thing here. I have not done any setting probability
in water Admin setup, which I mentioned you
in the earlier session we're supposed to
do for the windows. I'm not done because I wanted
to show you the error. And then after the, you'll see there when we executed there'll
be a link in it. And of course you can see
I've not done any settings. I'm not linked to any library, then you will understand how
to fix it, how to link it. That is a reason
I have not fixed it earlier so that if
I would have fixed it, you would not have hit my case. I would not have got error. In your case. You
wouldn't have got it and I don't want anything
to go in backlog. That is a reason I have
not done anything. I want you to
understand each and everything and how
to fix everything. So now let's link
the blue graph. Now let's build and run. I should get a linking error. Yes, I wanted to linking header. You can see here in the
console or in the blog itself. You can see undefined
reference to WSS tech startups or whatever functions we
are calling water. When those startup, the Lewis has started
then socket everything. It is getting an
undefined reference. Why? Because I've already
told you for the Windows operating
system and you poke on the socket programming
as well as client. Since we are using
different functions, we are using the
functions which are defined in the wind
Socket Library. We have to link
in our project to that library
nonlinear fixed edit. Because we have
building that library so that execution time
on the linking happens. Linking always happen whenever you are executing the code, then only the definition on the function
wouldn't reject fame on neither declarations
or whenever you're calling your
functions at compile-time, it will compile successfully
because I put a check on neither declarations
that had been received from the header file
which you have mentioned. You it got all the declarations for you, didn't get any error. But in the linking time it
will see the definition. This, you don't link it. You, you will get the
undefined reference that by executing. Now let's see how to
fix these errors. Well, obviously I'm not. I have removed those settings, build environment
settings, so I'll show you from scratch. For that. I have showed
you how to do that. Both settings go-to compiler, your go-to links
or settings step, good, you are having
other link options here. You need to give this library, this libraries for
Windows socket 32-bits. So this is for that. You have the user when
Socket Library and therefore you are doing
thinking and give me minus Lusaka do then just
save those settings. Now when you compile your code, it should compile successfully. Now it is saying that
see this message, we have given this name
for incoming connections. We have given this message here, actually C-out listening
for incoming connections. So sad, what is listening? Now? We supposed to write that code. So I said workload is running. Now, always remember, we have to reinforce the
server code and then climb because server is necessary wasn't without server
port if you directly run to be a problem because this is a one client will
be, I'm integrating. It should be always, you should always launches. And here I will be showing, since I told you that
we will be seeing the socket communication between the between server and client. Here, you can either use, you can run your server in one host machine that is one laptop and you
can learn language. And another laptop that is an another host machine
that is remote hosts. And you can do the socket
communication I'm having. I will be showing you how to do the socket server
client communication in a single machine. Suppose you are having
only single machine, then how you can perform it. So that is also possible. It is that you have
to do some settings, how you will create a server
process and client process. In this project, we
are using this IDE, which we are using
is code block IDE. We have already created
a project for the sudden that in this block IDE. Now for the client to create
a project for the client, we cannot create the project. The client in this ID itself. What that is in
this code block ID. In this instance
it says we cannot clear because at one time
one need this code block ID. We can execute
execute one program. We cannot execute two projects. I mean to say we cannot execute my picnic
projects in a single, in the same instance
on before block. If you want multiple
projects to be executed, then you should launch multiple
instances of food log. So this is only one instance. That is I have clicked
onetime code block ID and I got this instance. And here I've created
a project possible, so I cannot create another
project POC line and same instance on
the coordinate ID and do the
communication for that. You have to create them that you have in the code block ID. Create another instance of
woodblock ID and you have to write buggy code and then you have to do the
communication between them. So by default, you will
not be able to create the second instance of
the code mole sodium will be on event time. So clicking on the word
love to do to get new, new instance you will not get. Because by default the settings
is made in this manner that every time it will be launching the same
code block ID. But now we have to
run server and client in different woodblock
independent since upward loop. So for that you need to, you need to do the settings. I have already done the settings in my case, but for your case, I've been showing
you before writing the server program as the double-clicked on
the code block ID. And you have to
do that settings. And then you write
the server program, which I haven't done
yet, which physio? And then you compile the code, you run it and then second time and you click
on Code Block ID, you will get the second instance offered and you'd be right, that line code, the settings
which I'm showing you. Remember, you are supposed to
do it before writing them. Cerebral inhibitory,
full assignment, new double-click
on code block ID. You have to do the settings.
So how to do that? We get the multiple
instance of woodblock ID. Thus go to Settings. Then you have to go to water and water admit I've
already done so. That is a reason. Already the changes that are already there,
which I am done. While your case, you
can see here allow only one running
instance which is here. The check box will be checked. It will be checked. By default, it is checked. And I have already unchecked it. Because I have
multiple instances. Default, this check box will be checked for allowing only
one running instance. And that is a reason every time whenever you launch
code block ID, like getting the same
for block launched. Since this is check by default, I have unchecked
it because I want multiple instance
also the next thing that is used in already running instance that is also
checked by default. So just uncheck that also
you as opposed to uncheck the align on the man running instance as well as
using already running, unchecked both of them, which already I have
done that where you cannot see that
check mark on that. These settings are
required and check on it and then click on, Okay. Now I will create another
project for the client. And you can see
now it will allow me to create another project. I had again double-clicked
on code block ID, I got the new projects. So you can see one project is the one that I haven't
written the server program, and this is the another project. So it allowed me to create another instance of the woodblock not
project, it is allowed. So this is a one instance
of the coordinate where I have launched another instance on the codon by
double-clicking on it, I didn't get saved. Instance running.
State launched. No. The project for the client. So click on File,
select New Project. Click on Console
Application steps as team, just so you have two
dental cplusplus selected. Click on Next, give
socket programming. Then click on Next. Click on. It will dump a default
HelloWorld program for you. So I've already written
outline program and just copy paste here and explain you
line-by-line instructions. I've copy pasted here. Client-side coding is very much a CDF to simply connected. We'll see in just a second. Let me increase the
font size so that you will be seeing you. Let me close this so
that you can see more clearly whatever
instructions I'm mentioning. This is that line program. We had mentioned
though, credit files. Since we are using, we are doing for Windows
operating system. Now again, the main
function which you know, it is an entry point to start
execution of any program. You have to dump the
code here itself. Even though you can make
your function modulo, you can simply define all these things
in some function and you can call this function, but always in from the
mean function on new, you have to wonder function simply year I've done the code. I know you might be a metal. This WAC data, which
I've already told you, this structure is a second
argument in this WSS startup, we know what is WSS stacked up. It is used to initialize
them and Socket Library. In the first argument, the program tells
which version of the wind socket library
if you want to use it. Since we have to use it, wanted to use 2 version
I've been socket library. This is a false argument and second argument
is the structure. This startup function will fill this structure in which Devin
Socket Library Could pass. I will send the communication about a political information. It will send to
this program about how many number
of sockets can be created in other information, this structure can be fed when we call the bluesy startup. This structure we have declared, declared the variable of the structure in this
manner, WSU data. Now the second
object which we are creating is for the socket. Since me I'd be called
creating a socket on the client side and therefore VR in her
creating available on that. And then we are creating
the video before this but also structure because we will pass the order details. We've been IP address and the port number to which the
client should connect to. It should be connecting
to the server. So we have to write
that on the IP address. So in our case,
since we are running the server and client on
the same host machine. So the client side
should connect to the local boost
because in local host means in the same host machine, same was machine because in which the clientele
needs surface running. And because we are running seven and client on the same
host machine, therefore, we can simply give the IP address on the
same host machine that is a loophole,
wants to machine. The client isn't an input
servers running that it said you have to give the
same port number which the server
is listening to. Now I'll be following
the socket function. We had. I think the first argument
which I already told you, that is an Internet
address family. And second one is that
the socket type stream. Steam is unreliable
type of the socket and all the details about
the socket we had seen in the socket basics,
what are the features? This gene socket is reliable. One, right, is reliable. Everything I mentioned that. And then third one is a communication protocol
and stream uses a PCB default is 0 value. Now this socket will return
a descriptor to that socket. Descriptor that you
got you will be in when you bought the parent function,
you'll find pauses. As an argument of this, this socket descriptor human
past as opposed to argument. So what does these three things? Again, you want, since the client will be
connecting to the server. So clients inclined,
we have to fill all these details about the IP address and
the port number. Since I already told you
that server and client, we want to communicate through this all given the
same host machine in the single laptop, single deck slope itself. We don't want to remote host, we don't want to laptops, cerebral client and
learning. I'll indifferent. Different laptops know we
are doing programming and same host machine and saved
machine itself and therefore, what IP address you
will be giving in the line side, simply, we want diabetes of
the local host because local host of adding
the client is running source servers running quanta
running on the same host. When you are given this manner, it means no back edges. I've explained you that also
in the earlier session, it means it will
be connecting to the local host IP address
of the local news, whatever it is that we
have to solve that. And then we are giving
this address family and since insight of what is listening to the port
number 45555 and depo, we are giving the
same port number. If you would have mentioned
different port number. You don't have mentioned
that port number here it says on the client side. Then we are calling
the connect function. Connect function. We're passing this
first argument as this socket descriptor, which we got from this. And then in this
socket descriptor, Then second thing we're
passing this structure, then size of that, just
in the client side, we have to call
disconnect function. And once the client calls
the connect function, and once the server
accepts this connection, then the communication
from server to client, client to server can happen. Broadway communication
can happen. So here I'm simply sending it. You can also call the
receive function. But I had made it very easy by calling it on either
side function. So I'm sending this mental map, sending this hello you insane function and passing
this descriptive itself, and then passing buffered it, I have initialized to
the value that is hello. And then size of debt. Then I'm closing the socket
cleanup we have seen. It is. In order to close the
socket in case of Windows, we're calling these two
things to resources. So all these things
are required to close the socket connection
in case of Windows, I have explained you what is the purpose of the
cleanup and it is this is how this is the
whole product line site. Or let me compile this
code now click on Build, the parent, no arrows. So I think I should get the linking error
because I'm not done any linking setup to link
to the library when 32, your build and run. Okay, I have already
done that is the reason. Just a second. Let me cross checkered
settings by-law. Okay, this library
already is added. Actually, we are creating
the new and we are creating the new instance. These settings is already not. So that is a reason you
didn't got any linking it. Okay? So you got output here. This 2 second, this client, we have launch client. Now you can see we got the very first message
is connected to server. This message comes once the client side is
sending the connection, and once the server
accept a connection, then only you get this
message connected to server. So what happens is so
accepted the connection. So you've got this very
first message from the UK. Nine, it is connected
to the side of it. Then in the side of a client side we are
passing this message Hello. Client is sending
this message hello and we have all the receive
function from the server. So it should exit this
message and should print it. This message which we have, we are sending actually
from the client side. We are sending this as
Hello and undecidable side. Let me open the
server-side code. This is a server-side code. It is receiving the
message from the client, so it is collected on the buckle and we are printing it on
the sidewall cytometry, see the console on
the server side. So when you see the
server-side console, you'll see it say, it says client disconnected. It says net client is saying hello sources decline faster. Hello message we have seen and that is received
on the server side. And because I said virus has, but indeed that message
on the console, like lion says Hello, see in the service I was hired. Whatever it has received here, it was connected in Buffalo
and then it is printing. Here's client sees what
supply descending. Hello Dakota, it is
printed on that side. So that is the reason
you got hello. This is how you may have seen how the client is
connected to server. And I think passing a
connection to the server, server is accepting it. And then client is
sending the message and writing the
messages message sent. And then set about is receiving that message saying
that line said hello, and then we are
disconnecting from the then the client gets, got disconnected
because we have called. It depends upon how you have executed editing,
your program coding. We have since we have close
the socket of that client, therefore, it has
been disconnected. But always remember,
you cannot close the socket for the server and tell an analyst you
don't close the socket, the client because servers
on either one to which all client will
be connecting to. It doesn't seem like a demon. This is how we have seen
the communication of the socket sidewalk nine for
Windows operating system. I will tell you bought gone. You understood it and he
had seen the execution of the lecture.
I'm done for now. Thank you. Thanks a lot.
12. Socket Session8 ProgramExecution ServerClientCommunication Linux C Part1: Welcome to this new session for socket programming for Linux. So here in this session given
me writing the code for the Linux system side of our client socket
programming and we will be also executing it. In the earlier session, we have written the program
for the server as well as client using C plus
plus what the windows. And we have seen how to create
a new project in the IDE, in the block ID for the Windows and multiple setups
are required prior, accompany and executing the
program for cybercrime. We have seen and we
have executed it. We haven't done the
communication sidewalk line. Now we will be doing a server, client socket
programming in Linux, VM Linux system
using C language, and we will be also executing
it prior to the session. We have also seen mortality
difference or not in the methods for the
Windows and for Linux. And then at a very
minimum difference and set up what changes are
required for the circuit. We have gone through the
presentation and explain, you. See practical advice. Let's start here. The setup very first setup
required is you have to make sure you aren't having valid
index system in your case. And since we will be doing
the program so you don't need to install any code block ID. So here itself, there are ways
you can write your program either if you want to execute
in using the Dui window, you can install that. I have used a simple
command prompt. So what other things
are available by default in Linux or
have you started self, I don't need to install anything required because
already for the Linux, if you talk about the
linears directly, you can go to the
command prompt. If you are having GCC installed, by default, you
will get this GCC. Gcc is a tool to compile
your, the program. And you can also executed whatever output
you will be getting. You directly can execute it. The holder, this
output, this created. So I will be showing you each and everything
step-by-step. Also. In my case, I have shown you those machines since I'm having this laptop is configured
for the Window machine, I'm not having enough. But who make you explain? Who have you write the code for? Server, Client or Linux? I have also I have installed in my Windows system itself
or the Linux VM met. So we embed, you might be knowing it is a virtual machine. If you are having different operating system
here, in my case, I'm having windows, but I want to also write the
program for the Lena. So if you want for the
cross-compilation, if you owe one is different
operating system you want, you have to write the program. You can directly
install VirtualBox. And from there you can write, you can get a download the ISO, ISO image for the
operating system you want. So why my case I wanted
for the Linux system, because I wanted to
explain you socket server, client code communication
and execution in Linux. And I already have
Windows report. I have downloaded ISO for Lena so far you it's nothing
all that is required. You are having a Linux system. You can directly write the code. You will be having
the Communists decided Hat Linux system.
I'm having windows. But to also execute the
program for leaners, I have to install
the VirtualBox. Just consider you are
having the Linux machine. So even if you
install VirtualBox, if you are not having Linux, you can download
the image for that. And if you have made your
machine configured to linear, so this is straightforward. So here also, just
consider you're having abdominal for
the Linux machine. You will be having by
default determinants. Let's see how to go. So let's see the preview, what all things you'll be
covering in this session. There are different
socket methods of other server just
to repeat and chart. It creates socket. In server side you have to create a socket, then
you have to find. So all of these methods are common to that
for the windows, just in case you
can see that it's one method not present
in case of Venus, that is wx, a method
WSS data function. That function was
dead on NAEP or the Windows machine code as well as for the
client would bet. Alina's, I've already
mentioned that WAS startup, startup function which is required to initialize
that have been targeted library is not present in case of this Linux machine
that is only the difference. And these other functions which are there are almost same. Just that part
disconnecting Nina's. The syntax will be
different and there is some structural difference.
So I will show you. If the client socket
methods again, the same thing WAS data
function is not there, which is specific to Windows. That is to create a socket, connect to the server and receive data and
then disconnect. Then the methods and
structured data specific, new, specific to the Linnaeus know WSS Startup function
using Linux, which I told you this has
been done in Windows, then the closing function
is also different. In case of Linux, the Soviet have to just
call the close function. But in case of Windows we have seen we have to call socket. And that is also WAS like Nina required to
disconnect the socket. So all that function was there
only for Windows platform. In case of the Linux we are
having disclose function. Then the type of the
socket descriptor that is returned by calling the
socket function is different. So here, when we call the socket function in both
of the server and client, so it will return socket descriptor in the
window been basalts, it was the same type
of socket descriptor is different in case of
linear return in type. And in that case, often
Windows, it returns socket. Here, when we write the program, you will understand it I've
just done or what have you, I have just written
them all down for you. Then there are different. This socket address
structure type is different if little bit tight
differences there. Same methods or
data type is there. Specific to Linux? Since this socket or
destructure type is different. So this stock, you know that this socket address
structure, what we do here, you fill it with the details of the IP address as well
as the port number. Since that is different. Therefore, you know
that product or service idea calling
texted function. So in this, except by a function we use this
archetype, this structure. So since the type is
different, therefore, the, this will change
in exit function also for the client
side we call Connect. So again, we use this
socket address structure. So this will be different. The type will be different on a socket ID was struck dumb, it does use it ionic function. So even seeing them divide
writing the program, don't worry about it then
with respect to header file, the header files required
for the Linux will be different compared to
that of the windows. Now, these other difference, now let's start
writing the program or the server code and client port socket programming in Linux. Again, you out already, I'm assuming you're
having a Linux system here and you are, you are about to write a code. So I have made it flexible. I'm covering each and
every thing here. Even if you write
the programming for socket programming process
of applying for Windows, you can refer the
earlier session and if you are having
the Linux machine, then you can record the session. So for Windows also have covered programming
and execution and four units and publishing
so that you will be in 14 writing the
code for different, different machine or you
become comfortable with it. So that is the reason I have mentioned a difference
and the code in make you understand
the difference in IQ. Let's start. I will open my dominant of the dominant and we'll
be writing the code. Let's open. Just let me write
their personal. Okay. This is my dominant of the VM. Let me go back. So I assume you want, if you are starting the code
boardroom Linux machine, you are aware of the commands. This is like if you are
comfortable with Windows, you can go to the audio session. And if you are, you want to
write a program for Linux, you should be aware of
basic things like ls. What is Ls doing? So in Linux, we mostly
use this command prompt. This is our terminal.
Actually, I've opened it. You can see the name dominant. And I just, you should know basic commands in
the Linux if you want to write the code here, if you want to
understand how to go to back to earlier
directory or to display what Einstein told us in
particular directory. So I am, and you can see my PWD, This is my part that is my name. And I updated the folder name by MKDIR socket programming. And here if I do ls and I have already written
the code for socket, can coordinate socket
several court. So I will open this code
for you in this form. These are two of us. Instead of having C
files, president, I will go through these windows and I'll show you the C file. I'll show you each
instructions which are used. It is almost similar
to that of the window, just a little bit
different is that I don't, I don't want to start writing Internet every
instruction nine by nine, so I have already written here. I don't want to waste
time and writing it. You will already get
sick of it because almost everything is similar to that specific
function difference, structured difference, and a 100 different defenses there. This Ls. Now to start with
the server code, let me open this folder. In the SOC Server Update dot
c. Now how to open this file using this dominant I can
directly opened by VI said about update dot
c. I can directly open this file in this manner. You can see this is the
code for the server code. I'll make you explain. Even if you want to see
through the Notepad, you can go to the
folder and you can go your socket programming I have created and this is
sort of vertical. You can directly open it. Either you can open
in this manner. This is the same pot
or do you can refer that dominate every foot. So anything you can go? I think so. What is mood, how you can have? So this is more clear
actually, you can see here, so let me open it
in Notepad itself. This document itself. First of all alone, I'll explain you how to
compile it for my students. See the program, these header files I've
already mentioned you. This is first of all, the
server code for the Lena's. I'm already told you
the difference in the header files for the Linux and for the Windows and
the earlier session. If you have not gone through it, you should go through
it in order to have more single quotes. So these are the hidden
files used for the Linux, what a socket programming. You can crosscheck later. Then. This is a main function. So here itself we will have a main function where we
have written our code. So I've told you this main function is an
entry point to start. It's an entry point to start an execution of your program. So whenever your
program gets executed, that comes very fast in this main function and whatever or you will
be writing here, will be executed line by line. So let's see here
what we have done. So you can see here there are two variables by the
name server and client, and I've initialized to 0. Its data type is integer. This is a difference
actually post that is here. You can see here, this is Linux specific data vendors variables, server and client is
used here itself. So these are the
socket descriptor. So I told you in
this presentation, then we call the socket function the socket descriptor
which visitors returned. Its datatype is different. It is type in digital
in case on Linux, but in case of Windows, he had seen it as of
their types socket, capital SOC, QE2 socket. So I hope to you walk through that session if you want to
be specific for Windows. So this is a buck. These are the descriptors. So by this on me, my this
socket handle only descriptor. You will operate on the
socket tube and you call the different
functions like buying, listen, exit in the board. You will be using this adobe cause socket
descriptor for the server. This datatype is different. Again, the second thing
here I told you that the address of the socket
structure is different. So you can see here we
are writing struct. This, this type of structure. We are creating the
variable of it. That is server ADD
at this billion US. This is also Linux specific. This is different if you
compare to that of the windows. Now here, this structure, it is filled with, it is
having so many members in it. So I've told you
my dismembers are used in the because what happened in the
side of our side, I have told you we have two. If one, server and client
communication to take place. We have to cost of
buying the sidebar. If you write the code for
server, for the sidebar, it should bind to particular
IP address and port number. Once we bind that, that means, in that case, the client wants
to connect to the server. How I understand actually what is the sideways
we've had is the server by just
thinking with it, with the IP address
where it is buying too, as well as the port number. So therefore, the
reason we have to, whenever we are writing
the server or you should bind it to IP
address and port numbers. Intimate client wants to
connect to the server. It will be connecting,
it will be sinking with the same IP
address and port number to cut communicate with it so that this is n here what
we instructors doing, the server address, we are
filling the structure that IP address and port number
where the server will bind to. Therefore, this function name it as I have explained in detail
in audio session also. And I've gotten the
methods which are used for the units and for the windows with discussion
singing with a port I also, you have gone through
the session. Now. You can see I have written this IN ADD or any
underscore and you have explained you it same
thing actually if it is banned for Windows
also, what does it do? It means that it is binding to all the network
interfaces which are present in that host machine
where server is running. So therefore, that means if you are connected
to the land, it will have
different IP address. So that is one
network interface. If you are connected to Wi-Fi, it will have different
IP address address and that is different
network interfaces. So your sidebar will bind to any of the odd all of the
network interfaces, whatever you use
in your machine, who wisdom in this machine where you are
running our server. So it means that so
that we are giving this variable, we're
assigning this. And then we add writing
the port numbers. All times fight
this port number. So you can use all the numbers
which are greater than 102465 by three pi because still 1024 it
is already occupied. So if you use any port
number greater than 1024, so whatever you will be using the port number for the
sidebar where it will bind to. For the thrombus mindset, you have to connect to
the same port number. And this is a family
infant address family. So your air in it. So since we are using
IPv4, default, by default, if I underscored ion and this is the bind function.
We are using. This, we're parsing
this disk side of eye socket descriptor. And then we're passing this structure which
we have failure. You have to build
this structure here. We're passing your TO typecasting to this
types and update this. Then we're mentioning the
size of this structure. Then we are calling
the listen function. So we can see same
functions are there for the Linux also just type
differences that it is returning in type
socket handle menu. Again, it will be
listening in the passing this socket handle here
in the first argument. In the second, how many
numbers you want in the waiting queue for the connection requests
for different lines. So here, since 0, I don't want any other
client connection to be in the queue,
so I've written 0. You can modify your code apart depending upon the
requirement human poetry, and action from the
client to be in the tube. The current one is executed. You again give,
give that number. You will listen. Listen means it will be
listening to this socket. Then here we are
printing the message from the side-by-side that is listening for
incoming connections.
13. Socket Session8 ProgramExecution ServerClientCommunication Linux C Part2: I'm declaring one variable. I'm, this is n string type because it is a character array. Here in the exit function
I'm calling exit function. So once the site of
a buns declined, send a request to the server. It will accept it and
meant it accepted. Then whatever will be posted, we will be passing
the same socket handle which we got
from this socket. And the structure here, this is here we are
initializing as null and null. Here it will return
applying descriptive. Here, this will be different
than that of the right. As I also mentioned you, the socket handle which is
returned from socket function. It is used so that
it will be engaged in accepting the connection
from the client side. Whereas this socket handle, which is returned from except it will be engaged in read and write operations from
the network, the client. So both of them
will be different. One use for the
different purpose and also they are different. So this socket descriptor, which we get, it
will be related, maybe having the
data of the client. So even if you can use
independent manner, you're here and I
will be reading. So client is using the same type of board wherein we have seen
from the Windows. Client is sending some
message, say hello. And then this is the set of odd. It will be spin it accept the
connection from Dr. lines, and it will be
reading the essays from whatever the
client had sent to it. So here we are
calling the function. Here we are using
the read function. If the client descriptive
and this buffer. Here we have already
declared this variable and whatever client set sense will be collected
in this buffer, and this is the sizes
you're mentioning. Then I have printed this buckle. That is the message which
declined, descending. Then mm said, but by
doing it 00 this buckle. Now then I'm closing closing the socket which
is there for the client, and then client disconnected. So you understand what we
award except function, what it returns will be heavy related to
backplane socket. After the usage, I'm
disconnecting it. This is what we are doing. So in all most all the
things are similar. Do that Prado Windows
machine that we have seen? This is the code for
the server side. Now. Sorry. Oh sorry. This is this is an
old prejudice for overboard. Let me open their dominant. Yes. This is the code, I hope so you are aware
of these commands, which means if you want to
open through the gum on from, you can use this editor VIM, and you can open the file. So these linears come on. I assume you might be aware of if you are writing
the program in Linux. And all the methods I've
explained you which are specific for the servers, so we'll compile it, but let's see how to
compile this code. We have to use this
GCC, so I haven't, not installed anything
in this Linux machine. So really this GCC, It's a basic compiler tool
for compiling the C program, are directly available
whenever you install. Whenever you are
having Linux machine, you will have this basic GCC, pleasant the air so that
you can compile the code. Gcc, you can compile the C code. I didn't write everything,
just type gcc file, which I have shown you
what the server code, how to compile it
in the command from GCC and then this name
of the file and ankle. When I do ls, you can see it created a dot out
that this is mine. After compiling the
code which had got. Now to run it, I will
simply do not run. Now let me show you
what the client code. Now also one thing that
I've explained you whenever you have to do the socket programming
between server and client, how you have done what?
The Windows machine. If you use videos,
the woodblock IDE, I thought you would
not in this one IDE, wooden block ID, you know, you cannot create 22 decks, one project, and
one product line. And you cannot do
the communication between them if you want to
do on the same host machine, if you want to do this communication
between server and client on the
same host machine, then that is the same machine. Then you need to open
the coincidence of the woodblock ID in case
of Windows, I have done, I've shown you that it's
upward opening to instance, awkward block ID, because by default it does not allow
and we have created, opened it to instance
of woodblock ID. One instance we have created one project, quartered
or sidewalk, and in another code
block instance we are created at that row
object model code. And then we have done
the socket obligation. Now here again, I will, I will be showing you those socket server client
communication in the same Lena's machine. How I'm using this GCC, I'm using this dominant to
compile my code to execute it. So therefore, you don't
need to do any setup. You just open another terminal. This is one dominant,
wherein you will be learning the server code, compiling the code for the
server and running it. And another dominant we
will be running guard. Once we compile the client code, you'll be running into
another terminal. So you will be too short
or open to different, different communists
wherein you will be running one server was always you
should run the server. So sideways should be always
run false because that is the main Damon. Different,
different clients. So that can connect to it. If you don't run solver,
you run client node, it is not possible, you should not,
that will not work. So sad what should run first? Because client who
connect to the server, Then we'll need a communication stops to run sort
of I didn't plan. We will have open in nominal. I will show you your
let me do research. Yes. You'll be running this inside of our code in
another terminal I loop. We will be seeing
posts, the client port, and then we will be compiling and then you'd be
running the client code. But once the server code, just understand
one terminal will be running Server Core
and other dominant, you'd be done inclined code. Let me open another dominant. Dominant. You have that option. Now you can see
another terminal is, this is another
terminal is there. I will be going
through the code. Does the client code. Now,
let's see the client code. We have already seen
the server code. Again, the client code is
very much short actually. You can see here, does this matches
that line code, this, let me maximize it. This is only the client code. So first of all, the header
files you have to write for the debt will be different
from that of the windows. This is the header files for the socket for
the Linux machine. Then again, the main function
that is an entry point. Now in case I told
you we have to simply create a socket and we have to call the
connect function. And then we didn't
write operation. That is only the difference. That is only the small board for the client as compared
to that of the servo. Again, we will be
writing a site of Salk. This will be the
handle of the socket, which is of type integer that is different than
that of the windows. Here, again, socket address that is also defensive and datatype. Now we're calling
the socket function. So here, always remember whenever we have to do
the communication between server and client should have the same second argument which is passed in the
socket is the socket type. You should have the
same socket type. It can be streamed
type over it can be datagram type stream diapers. Using the TCP communication
protocol, it is reliable, whereas the datagram
it is using UDP, which is not relevant. So most of the time
he uses TCP on me. So both of the service side also usually when
you create a socket, this type should be
of the stream type. And if you are using
here the stream. So both of them should
have the same type. Either both of them to the extreme are either
both of them should have datagram type in order to come in order
communications to ductile, which means
settlement in plants. So we're calling
socket function. First argument, we're passing
Internet address family, then dipole of the socket stream and Lindsey Nicole, the
communication protocol. Then that will return a
handle to dark line socket. You have, you are creating
the socket product. Hindsight. It will. I have edited this
variable name. So I've written the name sort of salt because it will
be connecting to the server. There is a reason but this socket we are creating for them. Client. Again, destruction, which is SO I told you the structure
you have to fill. First of all, in the client
side will be writing the IP address of the
server, which is same. This IP address
should be the same to that the server is bind to, and the port number should be also seeing why I have given $127 No.1 and explain you. This is called as loop back
address because since we are, we are, we want to do the communication
in the same system. In this same system my server is running and my client
also I will be done eating. I am. Therefore, since it is the
same system echo this year, it means that it reports
to the local IP address, which is dead on
the host machine. In this lochia local IP address, the server is only also running. So therefore we are simply
mentioning $127 dot one. That means report to
the local address of this host machine
because we know that our server is running in
this local host machine. That means that it is sinking to the same IP address where the server is running. And the port number is why
five times, four times five. Because here we have buying the server to
this port number. If you would have binders, I bought two different
phone number, say 9994 times nine, then you would have given
here four times nine. Whatever port number you, your server binds to, the client side should connect
to the same port number. This is all we fill
here in this structure. That is this. And then when
we call the connect function, we will pass the first argument is the handle of the socket, which we return from this value calling
socket function and this structure which
we have filled with the IP address and the
port number and then size. And then we write
in the client side connected to the server, because after the
connection is done, then this message will be
printed from the client side, saying connected to this client is connected to the solver. Then we have, since in our program we are
sending the message. We are writing the message from the client side and we will be reading it and
thus server site. What message we're sending, we're sending simple hello. Here. We are initializing this string that is a character
array with this hello. And let me call the
right function. The first argument is
handled of the sediments out of the socket handle and then
second argument as buffer, which we are initializing
to this value. We want this value
to be passed to the server message
to be passed to the silver length of this. So therefore, we are calling the right function by
the right function. Mentioning in this
socket we have to send this message buffer
that is hello to the server from
the client side. This is a client side. Then
we are printing the message. That message is sent up
to calling this rapier, misspending the message
on the client site. But this backbone, and
then we are closing this handle and
then socket closed. So this is the code
for the client site. So you can see this
ready-made, simple and z. Now I have open
another terminal. Let us go to the substance. We have to always run faster server code so
we'll be running it. So I will open. I've run post-hoc
wall server code. How to run it by simply mentioning why I
mentioned this dot slash, because this means I am in this current directory
on the folder, and I will execute this. A dot out, dot out is present
in this folder itself. So when I run, I will
get the server side, this message that is listening
for incoming connection. Now the server is listening. Now we have to run our
client code one meter on. Once we run the code, then client should connect to this servicing
client disconnected. Then client should
send a message to the server and we
will be reading in on the server side you'll
see a welcome message that $0.09 will be displayed
on the client terminal. And you can see on the
side-by-side whether that message is also
read and printed in on the server side in
service I now we can see on the listening for
incoming connection, let us run the client code also. So let me open the
dominant chord. So post I will compile this client code by
simply this function, DCC and the name of the file. When you run, you'll see
just a dot out that is the output produced
after compiling it. Now we should execute it. So here you can see you want the message on the client
side that connected to the several vendors
message sent with buffers coming when the client is sending some message
to the server, then this message comes. So let us open the service. I didn't let us see whether
the message has come there and the information
has been updated. Yes, you can see after this listening for
incoming connection, this one mode we
can safely game on the server site line connected. Client says buffer is hello. From the client side, what I want to say
just asked you are you can print line says
but, but it's hello. And then we have gotten
disconnected function from that also from here. This is what we are doing. You can see how this
communication takes place. So this is just I'm
sending the message from the client and I'm
reading the message, I'm writing the message
from the client and I'm reading it
on the server-side. So you can write and read on the server as well as client. You can have any two-way
communication at allele. So you don't just
explain you the syntax I have I have written from the client side and I've
read on the server side. So you can do Weiss was
I and you can do both write and read and do the check. The chat from server
to client. I'm too. So this is what we have seen, how this socket obligation explains how the message is
sent and what all function, different structure,
different mobile header difference is doesn't. Let me move to the second. Let me, let me come back to my presentation will be done seeing all these
things which are there. We have that we are done with the server, client
socket programming. We have done in C language what the Linux and we have
also executed it. I'm done for now. Thank you. Thanks a lot.
14. Socket Session8 ProgramExecution ServerClientCommunication Linux C++: Welcome to this new
session four, et cetera, client socket programming
and see blood split quarterly nuts
with its execution. So prior to this session, we have gone through
the session for server, client socket programming in C language or Linux
with its execution. So we have written the C code
for socket sidewalk line, and we have done it's communication while
the Linux system, we have seen how client and server they communicate
with each other. Now, we will be diving C plus plus code and the Linux
operating system, and we will be performing
socket programming for cybercrime is no much
difference On need. The compiler will be different. So we have seen, we have used in the Linux for compiling
the C program. You have used GCC yet we will be using on GPS because that
is only the difference. And some functions that we'll be calling quarter
inputting and outputting will be different breast all the functions related to
the socket will be the same. That is no much difference. So we can quickly go through
the session as it is almost, almost similar to the set of guidelines I've been
programming in C on Linux. Just up Jens door. Three functions,
calling functions will be different as it is used, It's fluid to input
on the console. Let's see. Just to show you, like if you can do
the coding policy, you can do coding for cplusplus only the compiler two
will be changing. Let's go very quickly through
the session in detail. If you want to go through the previous session
which I had explained in detail the same program
and see what the Linux. So I'm going here to
ugly because it's simply the repetitive things on
the minimum difference, biological difference, and some calling
functions different. Again, the same thing here for the server socket
methods for linear, since we will be
performing this, that these functions separate
isn't creating the socket, binding it to all
the things if you compare with the Windows
machine will be similar, but one function is not present. For the Linux. That is, although WAC startup and when we disconnect
from the socket, syntax would be the difference
as compared to that on the windows for
the CC plus plus. Same functionalities are there there is no difference
in Texas also seen. That is no different
and socket programming using C and C plus plus on neither compiler tool and some
calling functions related to input and output
are different. We will be compiling
the code using g plus plus here in
case of writing, when you're done writing
the code and cplusplus. And then it'll be executing it. Now near the client
socket methods. Same thing I need to do as
a startup is not present. That syntax is different
than having the same for C and C plus
plus will change. The same thing with Dr covered
in the previous session. That is for the Linux specific, these are the methods and
structured data that is not a versus Startup function
used in case of Linux, as I told you now. Then the next thing,
losing functions different IW or losing them socket. We are calling the
function that as compared to the
windows that didn't Macondo glue socket
in WE sick limit. So that is different
in case if you compare with the
Linux, I'll see you. It is similar, is same. And a dipole socket descriptor, it is driven by calling
socket function is written. So this is a difference in specific to Venus
because for Windows, the socket descriptor and
then return recordings, the socket function will be different as
compared to Linux. We have seen that in
the previous session in the c programming for in the Linux system that we call the socket
function the socket. And then we got, get
the type of the socket handle is of integer
type in case of Linux, but in case of Windows, we have seen it as other types offered capital SOC Katie,
that is a difference. But for CC plus, plus same
functionalities is dead. No change in this. And then disorganized or striped
structure is different. Again, specific to the
Linux address structure will be using for the socket read and really
revealing diabetes. And the port number that
dipole that socket and restructured is
different in case of Venus as compared to Windows. Also a pet related functions
as saying for CC plus plus. Then since this
edit structured as a different type of
decided structure, indifference or
dysfunction is used. And so their website portico accidentally call
the accept function. We will use this
address structure. So it didn't have the
type different as compared to their
doctor windows on. So the client we're
calling connect. So again, incline,
I'm going to be called Connect
function inclined. They said DO structured
is used at the time of the debt is different
than that of the windows. Again, the header file, if you talk in terms of synthesis specifically
not so dead. Polynices was socket
programming is different as compared to that of the header
files. Window selections. I'm just rushing through this session because it
is a liberative session. Just I want to show
you if you compile cplusplus code and Linux and
what combiner tuners used. And some header, since we'd call functions to
input and display, that related calling will
be different. So Socrates. It all functions are saying
has come back to that. If you compare C
and C plus plus. So let us start
writing the code. Let us go through this talk. Cetera gland cplusplus
socket programming with execution of
identities may not exist. Go to the Linux
operating system. And then I will be showing what all things
we will be using. Welcome vital to
write that code in C plus plus n2. Combine it. Moving to the next. So I'm having or
when to Linux here. Second, let me give
the first one. Here. I will be
opening the dominant. Since we will be, We will become by writing
the code in the dominant. You know, I have
already told you in the previous session that in the other tendency
programming or socket communication in Linux, I have already told you that we are having the provision
of using determinants. So if you are having
this setup of Linux, I will show you and having, you know, the basic
commands which are used, or the Linux that is
very much important. So we have already covered WC commands and short in
the previous session. We will be writing
the code dominant. So let me open that. It is launching a minute. High-quality created the
folder boardroom, C plus plus. It's almost seem just wanting
functionally defense in. It says wonderful. And you can see now the
file which I have created, I've already written
the code so as to avoid the time taken for writing
each instructions. So already I have explained
each instructions and previous session
that didn't have written the code in C and B. Next it says go through it
if you want to go in depth. So yeah, just to understand what tool is used
to compile the C plus plus code and what minimum differences they're not
in socket programming, but when you call the console to read and
write on the console, just that function will differ,
whereas socket functions, as seen here, this file which you are
having in C plus plus language will be having the
extension dot cpp that in the Vedas engaged solve the C language when
you write the C code, we had seen extension
was not seen, but in case of the seat, Let's best extension is dot CPP. You might be aware of this if you have done the coding
part C plus plus, let us go to this. Now. If you see that though, if you compare to
the C language, if you competitive less
physical good C language, all the things are same. Just a difference of this
header file I have included in C plus plus because you might
be knowing this I O stream. This is the header in specific bought displaying and
inputting on the console. So like we have seen, that engages on the C
language, we use stdio.h. Here. You can just remove this stdio.h that is not required. So just let me you
can come in here. This is not required. Because here you're
going to be calling the functions that is
display on the console. It, you're calling
the function code. So you might be knowing that
when you write the code and cplusplus display any
message on the console, we call cout function that is acquired outputting
the message on the console. So this message unit
output on the console. And this out it is, I have used the namespace std. You can see I've
added the school using namespace std because this std standard
template library is that this function is defined. So therefore, when you
have two C plus plus, you have to mention in this namespace on this
functions are there. So we have to, first of all, I mentioned this namespace
and then we can see on, if you don't mention
this namespace and using namespace std, it will write it here. Then you can simply write as to the school it as a solution. So these functions, and I assume that you are now
in the C plus plus code. If you entering the
cplusplus coordinate the light that is basic
function to display it. I think this year and give the input on the
console we use C in. So in our case, we
don't not giving any input on the DevCloud. I'm not calling function to input on the I'm calling on me. See, I'll bring their message on the console so that there's only difference
here is the sulfate related functions are same. So if you see that this is a
cirrhotic coordination, you Execute your program. The execution stopped
from this main function. So whatever line of instruction, so we will be diving
in this main function. It will be executed
nine by nine. This is the same
repetitive session, just to mention you the
difference in C and C plus, plus. I'm, I have I'm giving
this session very quickly. The gourd here. As I told you, you'd be calling the sorted function
that is used to create the socket and several court that is Internet
entrance family. This is the type of the
socket it is streamed by. So we have bought server
and client communication. The socket is created
and both sides. So the type should
be same if you want to have the
communication between server and client is having stream type nine dots or you should
have this gene guide. Stream is at a liability
type of the socket here. And the third one
is a communication protocol default value is 0. It returns a descriptor
that is type in vivo. So this is seen in case of cn sequence every
time region which is used for socket programming in C language and as
well as sickness, but no differences that on me, this blue color display and input from the console
that only functions which we will be calling
is different in case I'll C and C plus plus in this
header file we have to include. And then this is the address structure
wherein the side road, we should bind it
to IP address and port number so that when the client wants
to connect to it, it can sync the same IP
address and port number. So this structure
we have filled in the server side with this value. And this Board
numbers are disvalue. That means it is, it can bind to on the
network interfaces. So I've explained you dip
in an earlier section. And then the sport numbers, whatever number you give
should be greater than 10 to four because still
1024 it is occupied. And you can use greater
than 102465535. Then you are calling
the bind function to bind sort of a socket to the IP address and port numbers only at spotting bootstrap data
two-year period here. Then we are listening this I'd rather be listening
on that software. This is how many number it'll outline connection
would be innovating. Then calling the exit function from the set of our
site will accept any message from a
connection from, let's say, accept any line connection
from the line side, that phobia calling
exit function declines and the connection then
the server will accept it. And then filtered version and other soccer descriptor
that is also of type int. This socket descriptor,
if you didn't write vocal all patient and
the socket descriptor, which it doesn't return is you're getting engaged
with dark line connection. This is what happens. And then that said avoid
what we are doing. We are sending the
message from the client. And thus I said we will read it. This message will be collected. We're calling the read function. This message will
be connected into small funds simply
operating, renting. You can see here the difference isn't just what
they're printing. So here we are calling
the function CL, that is C plus, plus
C plus plus language. And yet, displaying on
the counselors C out and this dentin double-quotes
whatever message you give, you don't need to give the format specifier
and C plus plus. And then you have to give
in this index outputting, then buffer, and
then end redness. You want it to appear to this
message on the new line. So this will become incoming
on the new United case on the CV gives slash n. But
in case I'll see bless, bless me, give END l and l that is appear doing Windows newline message
to come in the new line. And you can again, so whatever you can see here, wherever we want to display
Animals eight on the council, we're calling the C0, C0, C0 debt on these different as
compared to the C language, there are two lines
of extra code that is hash include iostream. You have to include
this header file and hash and then using
namespace std, because in STD on
me the CEO is dead. That's it. And then I told you, since we will be performing, said Let him client
communication. C plus plus in the same, indeed nuts in same machine. In that case. Of you'll be opening
the total minutes in one terminal and you get this as a dominant and one terminal, we will be executing
the code for events or discount bias of the
code is compiled and executed in one dominant
in another terminal. Once the client code is
compiled, we will execute it. And another dominant, both of the total water on
them should be running in different terminals and then they will be
communicating with each other. Let us compile this code. So here, this is a
different in C plus plus, we will be using g plus
plus compiler tool. In case of the C language, when we dug C code, we used GCC. But welcome finding
the C plus plus code. We cannot compile
the GCC because GCC compiler tool is used to combine uneasy,
Nazi, blessedness. C plus plus is an
extra add-on on scene. You just g plus plus. That is a compiler tool. You can compile the
C code as well as C plus plus code because
it is an upgradeable, a dozen upgraded version, that of the C language. So C language as well as C Plus Plus language can become filing by g plus plus Y2
outside is not bossy, but that is, you cannot combine your C plus plus
code using this GCC. You have to use g plus plus. So since C plus plus supports, supports C language alone, so therefore by G that
we're using D plus plus, you can combine C and
C plus plus code, but vice versa is not possible. That is, you cannot use GCC to combine the
C plus plus code. So therefore we will
be using g plus plus, and then we will be bilingual
or using the student. So again, it will
create the file and out I had before running it. Let us also see the outline
code that has opened a new dominant or the
accidents I totally butchered run in
different dominant. Now. Now, since I told you
though, C plus plus code, which we'll be diving really
have the extension to pilot inherit the
extension towards CPP, have done the changes for calling the input
and output function. So you can see here, again, we are having, this is a very short
code in a minute. You'll note that the
client code is very small as compared to that
of the salvo against the socket functions
as saying plus aqueous plus four C language
on media calling the input and you're calling the messy function to display the message on the
console leg is only different. Therefore, we have to include
this header file, iostream. You have to write
this namespace std. So same pink rest haunted things are seeing
related to the socket. So you are calling the
socket function in client. And we're saying is
we're mentioning here, so the same syntax, we're filling it
with the IP address. So I told you $127 No.1 isn't Lubeck
address that since we add me wonder
communication to happen in the same machine. Depth or the server
and client is running on the same machine. Therefore, this means a
Lubeck address means, this means this board to the local IP
address, local host. Ips certainly had diabetes on the local host
because we know that in the local host
server is also running, so it will revert the IP
address of the local host. And then we are mentioning the port number in the server-side, whatever number we give that
don't meet the client side, it should be sinking to the same board number in
order to connect to the cell. And also the IP address
should be the same. Then we go on
disconnect function. V bar is this structure here. And then we are writing the
message from the client site. Same message I have written. So you can see the V, V I'm displaying on the
council is different since we are doing this
coding in C plus plus. So I'm using the
CEO who display on the console and N dollars used to have them message
on the new night. Again. See how it is used here to want to
print the message, whatever the client is sending that we up ending
on the console. This differences
on neither rest on the socket related
functions are same. So you can understand if
you know the same language, you can start C plus plus
nothing difference are that in the socket related functions on nuclear display the
message on the console, the C plus plus because
quarters there that code. But pooping on the console. Let us Find the board here. So here are the combination tool I'm using GPS because
as I told you, we cannot use GCC to compile the code for the C
plus plus because gcc, because C does not
support C plus plus, but z plus the support
C because it didn't, It is an embedded
version of the sea. So therefore, you can
use GPS best to compile the C code as well as the
CPP C plus plus code. But you cannot use GCC to
compile the C plus plus four. You can use GCC on need
to combine the C code. I hope so you understood
the difference. Then let us compile
the code here. It is generating
a dot out false. We should run the server, then we should run that line. And what is their
daemon process? It should be launched first in except the connection
from the client. So now let us run the
code for the server. You can see on the server side and we're getting
this message that is listening for
incoming connections, sort of what is listening? Now let us run the client code which is dead
on the another dominant. Now, simply we are
sending message, we're recording a
right function message on the socket from the client, say the server-side DOM
witnessed stage will be updated. God connected and
whatever message the deadline descending to the survey Derby to
speed on to sodium. Then mutual using the socket. Let's Dando by AD and output
inductor underlined site. You can see here connected to the silver on load line site. After the connect function, you are outputting this message using CEO that is a
difference and C plus plus. And then once the
message is sent, ones me write on the socket
from the client side, we get them as statements. It's in with buffer
inclined handle. So let us go to the server
side and see whether the message has been received. You can see here that
in the syllabus, this is a server called
socket several code. You'll go gone this message ductus after listening for incoming connection
on the silver side, if you want them as age
as Glenn connected, client says, but what is hello? So this message, you
are a good thing on the output and then
client disconnected. Here I had one more thing. I have initialized. If you see here, that though we have two backward actually which I'm using here on
the server side, I have initialized to 0. Because if I don't initially, this 0 means it is
initializing on them. And buzz of the eddy, Brazil, you can directly, you don't need to write 0
every 102 ordinal a region. You can simply write
Connie racism 0, that means on the UN
initializing by default to 0. So this is very much
required because once the sidewalk going to receive the message
from the client. In that case, since if you don't initialize
by dipolar to 0, then whatever those
clients have, send a message on the celebrant you output of a new
displayed on the console, you will get that message, but extra vitae, which
thing you will also get. Therefore, we have to first
initialize this string, that is Eric character to 0. And then we have to whatever the client is
sending to the server when me, that is gonna didn't
Buff other and may display in on that
on the console. You will not get
the database venue. What you get so client
is saying only Hello, so it'll get her lawn. This is yes. Now we are done with this
socket programming board. Decide about applying
come vacation in Linux platform
using C plus plus. So hot drink C code. You can go through the
previous session that I've covered in detail. I'm done for this session. Thank you. Thanks a lot.
15. Socket Session9 UnderstandingHTTPServerClientCommunication: Hi, welcome to this
new section that is understanding that
should be server client communication on ECP. Here, again, the socket
communication we will be seeing between the HTTP
server and client. By the term HTTP, you might be aware
of what is this? Http. Http stands for Hypertext
Transport Protocol. And whenever we are
surfing the net, whenever we want to etch some
information from the net, we will be typing the link, will be visiting the site and we always give http or HTTPS. By deck, we will get the page launch link
we get in this manner. The information weekend fetch. In this manner, whatever
link you are passing, you are giving on any browsers. It can be the Mozilla, it can be the groom, it can be Internet Explorer. All these are the browser types. These are the client-side, application side so that we will be giving any of the URL, this URL, which will be Odyssey
link, which we, you give, suppose you are
giving Google.com and that is what will happen. You want to fetch the
page on the Google.com. So you will be a link on, you will be typing the
link on the browser, on the application
side underlying site. And this linkage us passing will be sent
to the server side. It is Apache,
Apache server side, and it will send the data
in response to the request, which is ridges given
from it was a side. So then the data will be
loaded on the browser side. This is how this
communication takes place. We have mostly go
and dive the link, but we don't know how it
works in helping manage this communication takes
place was simply be one summed data we fetch. Suppose we want to fetch some image to even be
typing the link on that, on the, on the browser. That can be the problem can
be genetic soup explorer. Then we will be getting
the data of the image. So how does data you
will get on the image? How this happens actually, you're just typing the link and you are enriching the data on age on your page, how this data you get. So behind, this communication takes place between the
server and client and server. A mutation takes place. And that is the HTTP server
client communication. So this takes place on the TCP. That is, we have
seen TCP session. It is a reliable protocol because everything
is provided here. It provides the
error correction. It is reliable because all
the data will be sent. Some of the data gets lost, then again, it will
be transmitted. It can be also notify
the set of us. So this is how reliable
communication takes place. It is also heavy weight. So we have seen, we have discussed about DCP. So here we will be seeing how this HTTPD be several
client communication takes place on TCP. So it does not take on UDP
because TCP is a reliable one and we want the communication to take place, it
should be unreliable. So therefore, it will
take place on GCP. Let's understand more. Let's go to it so
that you will be understanding in detail what
all we are discussing about. In our earlier lectures. We have seen, you might
be aware of how would this TCP server client
socket communication takes place because I have already explained what
well-known methods are used. Or TCP server, client
socket communication. And we have also seen that with code for the Windows and Linux, we have all sorted in the
program on the woodblock ID, this TCP server
time communication, socket communication,
and the windows. And we have executed it. With the help of this knowledge, we will be seeing how this HTTP server client
socket communication takes place on TCP. So this will be
very easy for you because if you have gone
through the earlier sessions, you will be at all, almost all of the
chord VI using in this socket communication of
each HTTP server offline, but with some little
modification. So you will be also finding
it more interesting. And let's begin the topics
which will be discussing people's understanding the
blog diagram of a medication. Then we will be seeing
how the HTTP client sends the request in the form
of the head and the NBC, What does this header in detail? Then we will be seeing how
this HTTP server will give this bonds to HTTP clients request in form of
header and body. Let's begin with the topic so that you will
understand more better. Now this is the diagram for HTTP server outline conjugation. So here you can see
this is HTTP nine, and this is the HTTP server. The request will be sent
from the HTTP client side to the HTTP server site in terms
of HTTP request message. And it's typically sidebar
that dance it receives don't. Um, input the data
from the client. It will produce this on it, then it will send
the data response to it to the HTTP client. So blindly considered
as a browser. The example which I
told you you weren't any link on the delta. The browser can be though room, it can be the infinite exploded, or it can be fired false. So different,
different browsers. You can giving
different links wherein the link is containing
HTTP colon slash. Let's suppose you
and you want to give the link WW, the
moodboard, google.com, you want to give facebook
bought common standard, I'm dot com any of
the link but you want the multimedia
related link. Whatever information you want a link to that you will
give the different links. That link which you pass in. That will be the
result client side. So that will be the link. That information will be sent to the server site
instead of on the site, it will response to that link. It will fetch, it
will constitute the data which it should be sending to the
client so that the, that data that was a site on, that data will be
loaded and you will get the page loaded on
your browser side. So all those data, it will be sent from
the server to client, which should be loaded
on the browser side. Let's begin this other
diagram, opaque. This is your web
browser, as I told you, it can be Chrome, it
can be fired, false. Sephardi, Internet
Explorer, anything, any of the router, this part is the client and
you are passing the request. That is, you're
typing any link on this browser like Google.com, facebook.com, and
today internet. This will be going to
this side where it's sort this web server
and application server, that is HTTP server, this mini constitute the data. Actually it will get the
data and it will send it in response to this request
here to the browser, and then page will be loaded. So this is how the
communication takes place. We see more detail now. Now let's understand what's happening in the
previous diagram. So HTTP client, let's send
the request to the server, will respond to it over TCP. The same thing which
I told you that this client send a
request to the server. That is here line, this is a client and
the server decline. That is your browser. It
can be any of these things. Chrome, Firefox, Safari,
Internet Explorer. It is sending the request, HTTP request that will be
passed over the TCP protocol. So this request will
be sent to the server, will respond to it, sending the data back. It will respond to
it or whether TCP. So it uses MQTT protocol, it uses TCP protocol because
it is reliable protocol. Tcp protocol is a
reliable protocol. Now let's see the example, the one which I've already
discussed, the browser chrome. See you when we give any
water to say we give http, www.google.com, adobe eyes,
giving any of the URL it. Suppose you are given the URLS, the Buddha
blue.example.com. This is suppose some link. It is having the default page. This link has been configured to have the default page whenever
the user type this link. This link itself
is configured to come to this page, default page. If it is configured
to this page, index.html, any of the
links actually it can be. Then what happens? So let's see. This UID, it will be
passed in this manner. This you added will be
passed to the server. This overbid process it and send the data back in response
and the page will be loaded. Let's see, one-by-one,
what happens? Now? We will be discussing
step-by-step. That is, how HTTP client will send a request
to the Apache server. So we have already, we're
discussing the example like we are giving any
link to the browser. The browser can be anything we have seen in
the block diagram. Suppose if you give example.com, as I told that some
of those links, they are at the ADA or default
configured to some page. Suppose this page, example.com, it's configured to index.html, that is, its default
played your venue. Give this link
that equality will be that human index.html. Then this link which you give on the browser what
will happen in that case. In that case, you would type
any link on the browser. And that gives us a GDP. That is, if you give
http WW.example.com, then STT pick nine. Ms, send a request
to that server. This you added a little bit
past to the Apache server. Here I mentioned this test. The data is sent to the server and this data that is this UI. This, it will be sent in
the form of the huddle. What is this header? Each and everything I
mentioned, the header. This header, which it is there. It will show up different
things in it. There it is. It will consist of the methods that are different HTTP
methods that are available. We will, we will be just seeing the list shock methods
which are available for HTTP at the very last
end of the session. The one that's going to
be using is a getMethod. This header, it cancers. If we are talking about this URL which you are passing
on the browser, on the groom, say you are typing any link, say WW.example.com. And what will happen
in the background. So postdoctoral in
the background, this HTTP client will send a request to that
practice over with this UID, that is W W.example.com. And this, there'll be
unwanted of either sending this request or their
practice at this client. It will convert this URL
in the home or header, this header it ancestor of all these things that S
is consist of method. There are different
methods like get, delete, the different
different methods. But the one which Is this, the getMethod will
see what we are all different methods to get
this to fetch the URLs. So therefore, in our case, since we are giving the URL, we're fetching the
USDA via using a year. The getMethod will be
fast. In this case. Then we'll be done. There. There will be
consisting of the method, and it will consist shop URL. You added it will be, that is in our case actually
died example.com. But if it is configured to some different pay
say index.html, then b hat, and then
the protocol version. Since is that we are
using the HTTP protocol, so it belongs with answers
from the protocol version. Then it will come
since the host, host will be like
WW.example.com. It's IP address for who build anything you are
asking what will be the host address offered that
month and the user agent. So this nu is that agent. It will be new for you, actually are whenever you
are using Mozilla, Firefox, or Internet Explorer, just understand that
different, different, different, different,
different, different user agent API using, if you will, you also
can test in this manner. You just try WW dot examples. The bill.com on Chrome browser and you check the user agent. You type it on, the fire is false, you
see the user agent. So it will be funny to
have them depending upon the dipole goes that
you are using VDC. The next slide to discuss more
about this header details. So I hope you understood
that when we are sending this new URL
link to the browser, actually buy in background, this browser will form on
this outline performer. And it will consist of all
these things which will be passed to the server in detail. I told you this header cancel
stock method actually, since we want to fetch the URL, the method will be
the GET method. Then the URL actually which
you were typing actually, and the protocol version, which type is GDP
Virginia using. Then you host actually what is a host IP address
and the user agent, as I do it for
different browsers, there are different user
agent on it see in detail. This is detailed in this
manner. By this thing. You will understand it and motorically or so
this is the header. So in our case we are
fetching the URL. Since I told you four different, different methods that are different HTTP
methods, in our case, getting method only
gets called because GET is used to fetch
the URL for this, you will get this as a method. This is a method,
this index.html. I told you that example of
the little blue.example.com, but in other default, zoning is configured
to this index.html. So you will get the URL
here in this manner. Then this header will consist of this protocol version of HTTP. Then it will cancers
the host or hostess, WW.example.com, which
we are parsing it, then the user agent. So this is a user agent source. I've always be at writing. Giving the link on the
Mozilla Firefox user agent will mean this man was a codon then it would
have given different. But on an inversion on
syntax on that user agent. And all the details about this, except language
disorder, these things. This is all the
header constitutes of all these information will
be sent to the server. So whenever you type any
URL to sin example.com, it has the call
configured to this index.html on the
Mozilla Firefox. Then internally this client will form this header in
this manner actually, and it will send to the server. Now also when we will
be doing programming. So here I'll explain
each thing about this HTTP server
client communication. And in the next session we
will do the programming. When I ran the code of a. Of you will be seeing
all these data. We will be printing
the data what does descending to the sidewise. So this data will be
printed on the side-by-side so you will understand
it more clearly. These are all the
things the client sends to the server
and you can get it printed display on the console of this
advisory board message it received from the client. Then this we have seen
now what happens when the HTTP request to that
server now see workmen, how sad, but it will send
the response to this guy. Now, this side of it has to see this header which the
client had sent to it. Now this outside where
that is Apache server, how it will respond
to this client. So it should also
has fallen by 70. The data in terms of this
header format, in this form, I told you should send it so that on the page
you will get it. Get the proper page
loaded with information. So this album, what
DO NOT IN case of the sidebar it constitutes constitutes on this information this information which
is which this side, wherever it should consist, stop if it is possible, there will be the protocol
version, same as GTP, which version it is using them, the status code and message. What does this, that is whether the link which the
user has given it has been successfully the sidebar
This morning successfully. There is any failure of the
network, anything, whatever. Successful failure dependent, dependent of code are
their message are there for that failure success and many different messages. So it will send
there it actually in this header that we
will consider report all this information it should consist and the content
type and content length. So what is this content
type and content length? In our case, we are giving the WW.example.com or default that link is configured
to index.html. Suppose so this index, our content type will
be of HTML page. Suppose it was some image, then it will have given
the content type is image. And what does this
content lends? Content land is how much
of the data is received. How much of the data ascending actually the server will
send to the client. That says the content. And this will be followed
by a blank line and the message with server 1% to
decline that you can write. What we will do in
our next session, we will write a program
for this server. We don't need to write the
program for the flight. Be using all the methods which
we have studied till now. That is for HTTP
server communication, instead of US aid whatever it's required to create a
socket to bind to, Of, listen to accept all
those coordinate will be writing and some
little modification actually that will be
this modification. So since I've been
with you, since, I'm telling you that
the server will respond in terms of produce. So since we'll be
writing the code up on Leda side-by-side, then mission. Write all these things. We should give this information from the server side in our code so that we get a proper
response to cancel, we get a proper page. So whatever message we are
typing on low side-by-side, we want that to be
displayed on the browser, but in the document said should be printed on
the browser side. Suppose we are sending
high from mom, the ascending hi or hello, buy anything from
the server side. It should be displayed on
your browser page as hi, hello, whatever message
you are sending. But we have two kinds. We have to not sense
and detect texts. We have to send it in
form of the header. And what this header
will cancel stop. It will consist of
protocol version. You have to give the HTTP
version in our old server code. Don't worry about this. Explain you with the board on. So this is just a description
so many start boarding, I will explain you what coding is required
and it is very simple. It only two or
three lines of code extract gold is required
to perform HTTP server, client communication
since you already know what is the
sidewalk or doc TCP, we have seen it in
our earlier session then just do the lens is
adult and it is simple thing because what we have
to simply constitute the set of vertical or fight, we have to constitute
that the message, what server will send to the line incomes in formal credit. That is only the difference. What did we showed
consists, Alex, I will mentioned you what
all things we have to give a new portal so you can just simply report
whatever I'm writing, whatever I'm doing coding
and you can understand it. What about the ones
you do yourself, you execute yourself, everything you I will let you know what
all things are required. So this protocol version
status score message, you have to give them
content type and then followed by blank
night and the message. So let's see. In this, this should be the format. Actually this is a
format picture or diagram and what messages
type I'll explain. I'll explain you in
the next session. What message will be
given from this side of it in terms of
this header files. So that whenever a given If we give them what we
will do in our case, how do we will run that? You will do this
communication between the browser window,
Apache server. We will simply,
since we are having, we are having the setup
of our machine itself. He wanted to test it, gonna arm achieve that. We will give the local
host address and the computer, the server, to listen on the local host of DynamoDB drive on
the browser side. Whenever we are giving the VI to giving the local who's giving the IP address
saw fired at machine itself. Then in that case, it will talk. And you didn't map to the
same port, server and client. Therefore, once we write the local host IP
address in order, but I was giving the port number sources on that port number where I'm applying this having
the same port number. So we will be by name the server to that port
number, that is 80. And we will be doing
on the client side, this local host, local host on IP address on the client side
and with the port number. Will listen, listen to
that client request. Since the ADA having the
same port number and it is mapped to the same IP address on the server. Should
we listen to it? And it will be accepting it. It will accept the
connection and then send a message to the
client which will be seeing on the browser
side text message. So don't buddy, relax. I'll explain you in detail
in the next session. Just to understand this is the hard data which we
have to constitute. It will be built right in our message from
the server site. Only this message
will be changed from the server's identity to write the entire message will
give the protocol version, and then he will give the status 200 and the status messages. Okay, that is all the
things I've successfully. There is a reason
we give this detail and this information like date. And then content
types of isn't EPA consider the example
of WW.example.com, then it is configured
to index.html. So it is the next type of
market is not the image type, so that is content
type and how much data will be passed from
the server took nine, that is the content Lin. And then a blank line and the message should be sent
from server to client. Say hi Hello by anything. This is the thing composed by the server site at
which this data is a header format which will be
sent to the client in order to page loaded on
the client side. So yes, once this advice center response as
shown in the previous slide, then the page will get load
on the browser line site, but the message sent
from the server, the same thing which
I told you once. The server constitute this
header and send to the client. And then the page will
be loaded on the side, on the browser side with the message with this
side, but it's sending. This is how we will
be proceeding. Now, we are done with understanding the concepts
which are required. And at the very last, HTTP methods which are present there that is radically different
HTTP methods like get, it is to patch the URL. In our case, this method will be used because we
are fetching the URL. So therefore they
GET method will be called when the header
is constituted, then another messages
and header header, that is to fetch the
information for the URL. Another method is put
that is to store to the URL method posted
on data to you. I didn't get a response
back and deleted the D2L. So there are different,
different methods of the HTTP. What, uh, what us,
we just require, that is the gate since we
have to fetch the URLs. I hope so you understood the
concept before stopping. Before starting with coding. It is required to walk
through this session. So basic things we
have discussed, we had seen how
this communication from the browser takes place
too dark side of both sides. That is, over whatever link you mentioned on your different, different browsers,
whatever, then this link will be parsed. That is, a request from the
client will be passed to the server and this
client in background, it will constitute
the header which will contain this format
if disgust you, it will contain the
methods since you have to fetch the URL and then the URL. Suppose it is indexed, suppose it is example.com. Default is configured
to index.html. So that will be the URL, then the protocol version. Since we are using std, one version of it, then the
host that is example.com. Then he was written, I told
you four different browsers, like Chrome for
my acquire falls. Dave derivative in
different new user agent. Then this information in it, then how does that
availability response? So he'd been also
constituted responds back in constituting this
header and body itself. So this header will
consist all these things. So this is required
for our case. We will be writing
the message from the middle rewriting
copy pasting the same or HTTP or phone, sorry, TCP server outline
which we have seen. We will copy the same
code parties is DCP. Dcp several naught
line client coding is not required only TCP server, we will write the code, the same code and
just unnecessary via sending them I saved
from the server to client. Not centered texts
like hello, hi, sand in terms of credit format, in this format that we
have to admit changed in according list
everything is saying. And then you can see
how could I ended up application how good hyperlink on how to
get the page loaded, how to get them message
displayed in index page format. In the web-based
format assessment, you are passing from the side, but on the browser side, this is what and there
are different methods, so be ready for a new session, but didn't we will be coding for HTTP server online
communication, that is HTTP Apache server, and browser communication on TCP in Windows VDB seeing
so be ready for it. Thank you. Thanks a lot.
16. Socket Session10 ProgramExecution HttpApacheServerClientCommunication Windows C++ Part1: Hi, and welcome to
this new section that is programming and
execution of a TPP. Our t-shirt would browser client communication
on the IDE, on DHCP. As in the previous session, we have seen the
understanding of the HTTP Apache server browser. Client communication may have seen what all things
are required, how the sidebar and browser
communication takes place, how the client, but when, whenever we are launching, we added typing any link
on the web browser. And the browser it can be, it can be exploded, it can be grown, it can
be Firefox, browser. I am deputation. Then this URL is sent to the sidebar in the form of the
header we have seen, we have seen the
format of the header. So please refer the
previous section if you have not gone through it, it is the understanding in detail before starting
this program execution on ID and doing this communication on the
browser and Apache server. We have seen how the client
will send a message to the sediment and don't
informal the header, then settler will respond to it. Same in dome Salk header, header and the body. Then finally we get the message where they hadn't decided, well, we'll send the message will be getting displayed on the
browser and the web page. We will be seeing this
will be executing, will be writing the program on the ID that is called block ID. Here we are using it as
it is freely available, and then we will be
executing it and you will be seeing how we are
doing the communication. Let's start. Now the program statement, which I have mentioned
now that on the browser, what we will be doing
this under browsers. Suppose you are using
a Chrome browser. You can use any browser. In our case, we'll be
using Chrome browser. And the user gives
the link like this. What is this link? User
can give any link. So by I've given this
link because I want, I want mine to take the communication in
the same host machine. Bede writing the code in
the cell in the manner undecided voters buying to the IP address of the
local host itself, of this machine itself. And it will be binding
to the same local host. And the client will be then wanted to connect
to the server. So we have to give
the same IP address. So I had wondered
who told you one to seven dot 0 dot one, which you give on
the client side. So all these understanding, writing the program
as I told you in the previous session also, it requires the knowledge
of TCP communication, which we have seen
socket programming, which we have done
for the windows. We have done set of
online communication in a previous to
previous session, we had seen how to do so if
you could written the code for the server as well as client and then
the communication. So I have old
waterfall methods are used for server-side
end product lines. I like volume. Then it needs to listen and then except under syllabus
I've seen on those. So you have gone through
all this session. You are going good sequentially. Almost decoding which
we will be doing. What does HTTP instead worth? Nine, will be using the
same coding which we have done for the TTP socket programming server
client communication. But a little modification might be a one-line modification on height of sending the message
from the server to client. As we have seen, if we have to do the communication for our, for that stock
certificates are worth nine communication and message. We should be done so it should have been
the header format. Server should be giving the response to the
client in FOMO, not as in pretext. That is only a modification to three lines of code rest older. What will be the same
for the server site, which you haven't
done further PTP, which we have seen
and executed on. So we don't need to
write that line. Ford hillary, we have to write only the server port lines
and you ingest typo, you widen on this
could own browser, this particular IP addresses, it's a loop back address. That means it is this addresses on this local
host machine itself, whatever the IP addresses there of the local host machine, it is that on the IP address and port number which
we are giving a 0 AT, we know that this is specific to HTTP will be giving the board
also for the server side, this is good line saying
wherein we will give this URL on the Chrome will
not write that line code, not required this unit to open this URL and that URL
only which are open if you want the communication
to take place on the same host machine for
this line. So this minima. This will be, and I
think to the IP address, local IP address of
the machine itself. So give this IP address itself. And this port numbers are simply the client will
connect to the server and said What about whatever
message we're sending from the service via sending
it in the SOC credit, consisting of the Haggadah as well as the body to
body will continue. The message has been
also you need to pass. And then output. That is on the phone display, you will be getting output
whatever the sockets, whatever the server
sends to the client, the message like high auto, welcome to the
socket programming whatever messages
over centralis. So starter code so that you
can isn't he understand? This is just the
program statement. What I told you. You have to
open this link on the room. This is the applica, this is the client application
that was at application. Then the request will be sent
to the server and server will respond by
sending the body. And then you will
get on the display the message which answer
was and students. In the page, it's an end also we can see
in the command wrong, like when you run cerebral code, you can see what all
client has sent to it. We have seen also that in
detail in the previous session. So let's see here then how the communication occurs between the browser,
client and Apache. So when we give this but this
link Endo Chrome browser, then that link is sent
in the form of header. I have already
discussed this message. This I saw the link
will be sent to the clients and the clients
and we're typing this link. And then client will constitute, will create a header, will be sending to the server. So it will be constructing the hidden and
then sending to the server. We have seen how when the client sends constructs they're
headed, how does it loosely? I have seen, in that
case the method is done. Then we have seen it
gives that result. We have seen, then there
is a protocol version, then that is a host. Then that is a huge region on the older format in which
a deadline sense to the server in terms of
header we have already discussed previous to this
session, please go through it. And Dani, I mentioned it, sends the message to the
seventh times I've heard it said what should respond
to this client also, in terms of header itself, I didn't body format, it's just repeated this
unimodal sideways and stimulus sense that responds to the client and the server
sends it in that line. So it should be in the
head and body format. So we have seen the server will be sending this
proof of all virgin, then the status that it
is successful or not. So status number of status
message in this map format, then this detail dates,
identify content type. So in our case it's
simply text message. If it chose the content
type is text, HTML. If it was the image, then it would give benefit
and then content land, that mean, that means
how much data is transferred from the server to client side and then
non-blank lines. And here you will be
writing the message. So let us see how to write them as h
from the server site. There have been beyond the
change which is required in addition to the board between
a scene or the TCP server. Then this is a message which we need to send from
the server to client. I'm just mentioning here in this presentation and
then rewrite the board. So then it will make you
a z to understand this revised or the little bit concepts, alcohol
communication goals. Then there is a reason
I'm just going, going through this presentation now this message,
what you will send, you just don't correct
indices are adding or you can define, you can hash define max, sum size and you can hatch to find its eyes to this number and you can read the signs here. This is just a simple Gooding
to understand the concept. And then what I'm doing, I'm initializing this
string to this frame. This is just a string
that is the message, this is Ariel characters
and I'm writing string copy and I'm
passing this string to it. So as I told you that, as we have seen in this slide, that does, I should
send in this format. So this details on me, I have filled in
the message that is protocol version than the status numbers Davis message and this date server
content and content. And so if you see this message, it is bits on the HTTP, then their version
of the protocol and the non-profit status
then okayed it as a message than the continents and then it's 47 content. That is, how much data is sent from the server to client content time that
it takes to steam. And then we add in
the body actually, then there will be a blank lines of slash and there
is a new line. And then body I'm
writing hi from tsunami. I can write anything
I'll be writing. I can write boning
socket programming, hello or whatever message
you want to censor. This is a message with students. This message will get
displayed on your page. So this is what you will be
sending from the server side. So let's begin our code. So you need to install Code Block ID is freely available and
it is an open source. You don't need to
buy the license. It's very easy to install and just go to the download site and just install it and start
programming with it. Let's begin. In my case already I'm open before menu and double-click
on the code block. You'll get this page. Let's create the project new
project console application. Click on Next, C plus plus, then the name that is here. It is. Going to give it
a sensible name, then click on Next, then finish. It will dump on the call
Hello World program for you. So let me increase the text
size so that you can see whatever you will be
typing hill just a second. Jews will be very big. Let me dive a copy
paste the code. I've already written the code. I don't want to waste
diamond typing single liner, like explain each line. So it's only the
repetitive code. Simply additional this message which I have shown in
this presentation. That's it. So let's open. I have copy pasted it. Okay. This is the whole code, so this is not new for you. You have already seen it in the valuing the
communication of TCP. Let me revise it. 12 like extra line in case of HTTP server
offline communication. What we are doing first of all, our program execution starts
from the main function. Again, the reason seeing
the lumen function is an entry point to start
execution of any program. Whatever lines of code you
write in this main function, it will be executed
line by line. So now we have to declare
these header files. In case of the Windows
operating system, it will show that we can use
the functions from this. Whenever you're calling any
function, using any function. Since I did find
you have mentioned it won't give any compiled a meadow string actually, that is this a real
book character and we have simply initialize
it with this format. I will explain you
this the same format. Yet I'm piping the messages, learning from learning
socket programming. Then. This is WSL data. So you have already
seen what is WASH. me. Revise it quickly. So this WAS data is used to initialize government
Socket Library. We have seen this WAC d tau, that is post-op all this data, which is that it is a structured crossing the structures
in second argument. So what does this structure? So first of all, what is this function,
as I told you, it is used to initialize them. And Socket Library, zipper
pulls off this WSS data in which the first argument says on what the program
wants to use, which login on women
socket library. Since the program wants to
use the version 2 we have to give in this format make one and then round
bracket two comma 0. Then this second argument,
that is Ws data, that is a structure
that is this. You have created an
object of this structure. That structure. So here
we're passing that. You are mentioning the
address on this structure, so it gets spilled
by this function. What is the purpose
of this structure? So it will say this diamond salt library will pass the critical information. No program saying how
many number of sockets can be created and other
necessary information. This is how it gets built when we call
this target function, which is used to initialize
the wind socket library. Then we have seen on this
ROSI and you need to create a socket by calling socket function three arguments
or their posts argument. This is an Dennett
interests family. It is EOQ underscored in a second is a type of the
socket type. It is a stream. We're using a reliable
socket communication and always remember
since we are doing the communication of HTTP, you should always take
place on TCP itself, that is VCB rack where
you have dimension. Do you see music
communication protocol? You have already seen in
socket to be six session. And you mentioned the stream
type and then the zeros. This is the default
communication protocol. You guys in a chaser 0. So now we have
created the socket, now it will return the
socket descriptor. So by this descriptor, we will be calling
the bind function, will be calling the
listen function, then exit function by
this descriptive since we will be binding to this
socket descriptor socket, then that piece of
code is this one. This, we have already seen
that this is a structure. Add R. So it is, it is a structure that
is here we have written, although tight, this one, this is a structure
and this is a video, a bit of a sphere
created you have, I told you we have to create
new advantageously get the socket descriptor
post by calling the socket function and
analysis on a disk news, saga, descriptive
and Nicole the exit function we have already added. And this this structure. In this structure
you'll be filling the IP address where this
Edward needs to bind to, as well as support normal, all the necessary details
you'll be giving in there. That is what you are giving IN a DVR and exclude
any unintrusive. I have explained in detail
what is the meaning of this IP address to which the server should bind to is
we have utilized to this. What is i an EdD at
underscored need can be binding to all the
network interfaces in the same host machine. So if you connect, if
you're using none, It is having
different IP address, is independent
network interface. That IP address the
server again by infill whatever you're using to
connect to him in the neck. If you are using land out, if you are using Wi-Fi, Wi-Fi and having different idea, a different network interface. Again, if you're using Wi-Fi, then it will, it can bind
to five-year dissolve. There it is. It can be buying two network
interfaces which added then, this is what we
had mentioned that then number we are
listening dub. Sideways should bind
to this port number is 0 AT for the HTTP connection. On the client side, it should be connecting to
the same port number. That is, what is buying two. So this is very much important
diabetes important number that line should be
mapping to the same one, should be connecting
to the same one. Then this structure we
have felt we are calling the function in which we are facing this socket descriptor. We are passing this address. Disruption actually
had fairly over diabetes and the port
number and the size of it. Then we had a calling
the lesson function. Now, you're listening. Listen function
again, we're passing the socket descriptor
as opposed to argument. Second argument contains
known how many number of the client connection should
be in the waiting queue. How many decided what again, process actually one
by one and Ken process once the one is completed
communication mid-month line, then it will be processing the another line to how many
number of numbers it should be there should be waiting of client connection site but accepting declining
line connection site, connecting to the client. So how many number of client requests can be there
if there are multiple lines? So if there are three lines, we want to be on,
Connect actually, so they should be in the waiting
line is being processed. So we can mention that number of nine condition that
should be innovating. You mentioned zeros since we want only one
connection after time.
17. Socket Session10 ProgramExecution HttpApacheServerClientCommunication Windows C++ Part2: Once it gets a connection
from the client side, it is listening, and then it
will accept the connection. So you are in past the
descriptor of the socket. We'll pass this structure
which is empty. This gets spilled when we
call the exit function here, the details of the client will
be there which IP address, port number and all that. This ISO for destruction,
checking this condition, whether it is successful
or not successful, then it will return on load is crypto dividend
descriptor of the socket, new descriptor of the socket. So why do descriptors
are required are to you the first
descriptor which is dead, it is required to x to listen. Actually funded independent
connection request. This will be engaged
with that of the client. And the socket is could've DO is used to send and
receive the data. So this will be engaged
in this, in this work. So therefore, this
will be different than what we are doing. Here. We had receiving the
message from deadline. So what message
here you will get simply since we will be writing, typing, or writing that, I've been a link on
the Chrome browser. As I told you what, you will be passing just
a local host port number. In that case, this message, but it'd be passed from
client to server incomes of former Soviet above
Bassanio link. So I told you that it
should be fast in terms of our header comments
from client to server, the message will be
passing handling have seen that header format
in previous sessions. It should be sending
the method and there should be U1, U2. It should be the protocol
version cost upon the method. Then it should be the URL, then the protocol
version, and the host, then the User-Agent headers. So whenever you'll be receiving that message
from the client, that message will be received in this string
that is about four and we're printing
it so you will get all the things printed
on the server side. What client sees that
is at hided format, that is about the motion on the HTTP then about the
URL, then about them. About this, about
the method possible, you will get the method,
then you will again though, URL and you'll get the HTTP version and who's the user region,
you will see that. And then, then the sight of God, which is sending the
message is this one. What does this
message we have seen here and we have
felt to this one, that is we're passing also the response from the server
in the header format, not a simple text message, not hello, hi, like that We are. You have to write in this format itself so that the message which will be sent
from the server to client should be
getting the display. Display, which will
get on the console should be the inner
web page format. So that will be a
passing the login here. Then those datas, numbers,
status, message content, and how much data has bonds
forms our deadline then than ten types into detects
SDM and the main body. This message or this react passing simple message
learning socket programming. So this should be
displayed on the browser. Once though sediment gets
connected, do it at the line. Client descending
the complication. Like client, we are
launching the URL. And then you add a list obtained from client to
server, informal ******. And then we'll also send this message and formal
credit and on the browser. Finally, you'll get the message
whatsoever since this is what the parsing thrombo yet from the server to client this message and then
we add checking it. No editor is that if it
is a message meant to 0, then we are closing the socket. So this is all coding required. What HTTP server, we don't need to do the coding or client, simply you need
to type a link on the browser that is only though or message
which didn't listen. And denominator compile
the code. And let's see. This is combined
the current file. So here you can see no mitosis present and let me just try. New ideas are present. Now you need to run this
program by clicking. Know how you want,
you have to go to. I have already told in
the earlier session, also, go to the View. And then in the loss, you have to take this box. Now when you give a bill, actually when you do build
and run, in that case, you can see here the
server is running and it allows it asks you, this is a viable whether
you want to allow Nexis? Yes. Now the server is listening
for incoming connection. Now we have to send, you
have to open the URL. You have to type a link on
the link on the browser. That will be the simple, as I told you, it will be local IP
address one to $7 dot dot one and the port number
80 retrieval type this link on the browser
that is at nine site. Then the communication
takes place to server and server will
send the message in terms of heritage
and mitigate on that browser that message
like what we should get. We should get this one that is, whatever you have
given them a message on the body site, learning
socket programming. Let's see, Let's do it. I have opened up and
I'm typing this URL. I told you we have
two cotyledons, one to 710 No.1 colon 80. This is the loopback address, same IP address of this
local host and port numbers in the serverless bind to this IP address
and port numbers. So in on the client
side we should give the same one we are giving, then just double-click on it. So here you can see
we got this message, I double-clicked on this link. I got learning
socket programming. Now what happened? I have died on the browser, Chrome browser, this
particular IP address. The port number which
decides what is binding to simply and this
message God received, whatever the client is sending
the water, do the service, and then it will,
it will convert, find itself will convert this URL before
sending to the server, will convert it to
the header format so that in the service I will
receive that message. So let's see that message. What we got here, you can see decided where I got the message from the client side in terms of header, whenever you add a new
passed here in IVF, IP address and the port number. So it got converted to the header format and it got printed on the
software side, whatever client has
descending to server. The message. Here you can see as I told you, all these things that his
client sees this method, the protocol version, then the host is this,
then user agent. So this decline descending
to the server that we are printing on
the server-side. That as you can see, we have
seen in this program itself, just as you have seen in this
program itself, has seen. That line says, actually, and the other side, what is receiving the
message and we're bringing that is year both in buffer and we are printing
it on top, unsold. So that is a reason we're
getting all this message, whatever the client is sending to the server in
terms of header. Now, the client, then the server actually once
it receives this message, then we add again this sideways, and then the server
is sending message. Once it receives message
from the client, then the server will respond
back by sending the message. And this message
we have seen here, we are passing what
we are passing this message and dumps all kind of format
in the same format. But we are writing
all these details, this Fama Titus, different photos and for the
client or the server. First, there will be the
protocol version than the state. This number is Peter's
message, content type, content length, and
all these things, then with the bank
and then the body. What message? This message what Southwest science server sends
to the client, we gotta displayed in this base. So you can see regarding
learning socket programming. So this is a two-way
communication which took place. This is how you need to run. One more thing to mention
actually, for you, if you have never Rodin the socket communication
in your single machine, same machine might be whenever you are
writing this new ADA, end up port number you
might be getting as editor. Actually this is
very much important, so please make a
new download it. You might be getting an edit actually permission
denied because there is a firewall actually wherein it won't allow you
to communicate. Can happen. It can happen. It is allowing, but
if it does not allow, you, it gives the
permission denied. Actually, in that case, you have to do some settings. I've just mentioned
you mentioned it now so that it will
be helpful for you. So don't miss this DOM, which is very much important. Might be few phases a problem, you can fix it simply. You have to just a second. In that case, you have
to open the notepad. You have to actually, it's not allowing you to
communicate actually, and that is an error actually connecting to the
local host itself. So therefore, you have
to modify the host file. That host file, you don't have the permission to
modify it as president particular location that I will let you know
now that host file, you have to add one
line that actually, so that it can
connect to the host. That host file which you will be modifying his door is
not having permission, so you just first need to open the notepad
in this manner, return of money,
you have to write, runners administrators
will ask you, where do you want to allow? Yes. Then just I will. All right. This
line actually that is one to $7 dot
one and then local. This is the format. And
I will be saving it. Here. I will be
saving it by the name as with, ST is forced. So what will be the
location of it? It will be C. Program finds list. I have to go to C Windows system Thirty-two drivers. Then EDC. This is a location vet and I
will need to save it. And then this is the, I need to save it here by
clicking on Save. I've already saved it. Actually, I don't
want to again save, so it is already see,
just click on see. Once you click on
Save, in that case, this will be aligned you to avoid dental permission
denied problem. This will allow you to fly. There won't be a
viable actually, so you can communicate
over this local host. This is only the setting
which is required. Now, back to the presentation. Now we are done
almost with this. So yes, we are done with this HTTP server
nine communication, that is HTTP Apache
server communication with that browser
outline we have seen on the idea and
here executed it. So you can see how the communication takes
place and you can see very minimum changes required
with respect to that of the TCP communication
only we have to send the message from
the server to client. In formal pedal,
we have seen how, what is the format of it
and hope you send it out. What are the session
we have seen? How when you give the URL on the browser that
is at ground Chrome, you can use any browser,
firefox, anything. Then how this client sends
the message to the server, it will be
constituting a header. We have seen that by
printing it on top. Server's identity have seen how server side code,
which will be writing. We will be sending the message from the
server to client in formal kind of you
have seen or talked to send it in either o program. And that isn't dumps off this. And then the message
which the server sends it will be displayed
on the client side. This is how the
communication takes place and we are done
with this session. Thank you. Thanks a lot.
18. Socket Session11 ProgramExecution HttpApacheServerClientCommunication Linux C: Hi, welcome to this new session. Polyphemus operating
system hadn't, we will be doing another program for having the
communication between HTTP, Apache server, as well as browser client communication
using the C language. So earlier to this session, we have done one more program
in Linux operating system. We have seen the
programming using C as well as C plus plus for me, I've done the communication for TCP and client communication. So in this session, in this session I will
be explaining you how to achieve HTTP Apache server
browsing online communication. So here what we will be doing, this same program
I have done for the Windows operating
system using C plus plus. You have gone through
that session also here, depending upon your choices, whether you are having the
operating system has windows, you can record that session and you can write the
coding for this. Should be a party several growth than avoiding
earlier session. If you are having the
Linux operating system, you can refer this session, but we'll do the same program for the Linux operating system. What happens in this edge
to give you about Di Salvo, rosa client
communication, a shuffle. The user will be giving
a link on the browser. Browser can be anything, it can be the more quiet
box it can be grown. What will happen in this case, as this browser is a
client application. So the request internally
will be going to the Apache, sort of odd, will be in
terms of the header. And then server sends a
response in terms of header. And then that response will
be there with the message, whatever the server
wants to send to the client it all that will be displayed on the
page on the browser. So we have seen, we have done that
understanding of HTTP Apache server browser in
our earlier session there, in our understanding
of this session, but in Iceland you
the concept what HTTP Apache server
browser outline how this, how would the client
will send a request to the server in terms
of parallel format. And then how In send a response
to the client in terms of her that embodies all explanation
covered in one session. That session you
can require it for this Linux operating
system also, and also for the Windows
operating system. And then I have covered
another surgeon for the Windows wherein
we have we have, we are done with the
programming and execution on the woodblock iodine wrinkles here will that do for the Linux, will do the programming
Polynices and we'll execute it. But handsets, understanding of the concepts you can report the previous session I didn't. I have covered basic
understanding of this, how Apache server and client
communicate in terms of sending the header and how it responds the side of our gifts. So you can understand
the concepts returning the earlier sessions, which are uncommon for
both Windows and Linux. Well, let's begin here. As I told you, what we
will be doing here, I will be using the buyer
quiet box as a browser. And I will be giving this link. This link, which I'll be
giving us simply, you can, you know that this
$127 dot 0 dot one, it is a loopback
address. Explained you. Loopback address means
it is referring to the IP address of the Lucas
local hoods my chain. So this is my laptop wherever I will be giving this
link in my browser. I've had every dimension, this $127 dot one, it will report to IP address of my local machine off my laptop. It simply means that, and this is the
port number 80 AT this browser means you
deserve client application. Now this line will
communicate with them. So an outlined is
sending this link to the server to server that
is now part two servers. So I have explained in that earlier session maybe never going to
explain the concepts. So I have explained how
this client will send those over in headed what all things will
represent in handy. If you have to go
through the detail, please report those section. And then the server will send
a response to the client. So simply you will
get the whatever the server sends a message
will be loaded on this. I was at Brown said that
is on the fireball. So we have also done
the programming and another session for the
Windows operating system. Now here you will
see for the Linux, this is all what we'll be doing. Simply give this link on
the application side, on the client side that
is on the browser side, use it that is a Firefox. And then internally request will be sent from client
to server in cell itself, I will give them
message in terms of displacements in dome top header format
and what body format. And that will be loaded
on your browser, whatever the server sends
hello message that will be displayed on your browser
that is on the client side, whatever message or if
the socket program, anything, whatever
message that was sent in. It will be displayed on the
page, web page Walmart. This is what we will be
doing in our program. Then here, this is just an explanation
what I have told you. In terms of high doses,
you can go through it. Then the lingual sending a formal product to the
server from the client. And in response, I will contract message and
formal credit and body. If you have to report
the proper format of the header and body referred to earlier session understanding the
concept of program. Programming for HTTP
server outline. You can just understand, go through that session to understand the concept
in more detail. Then. This is just the head, a format which is sent from
the server to browser. So this is just a format
which I have sent, which I have displayed here. The sidebar sense whatever
that line descending or you are giving a URL on the client side that is on
the ground certifiable. Then this then the
request will be sent from the client to server.
Farms are parallel. This is what the server will
send a response to decline, and this is every response. So this is the response type
of the head and body format. Here you can see I told you more disparate isn't in the
hair determined server sends to the client, wants to call the version of the protocol we are using
the HTTP then the status, whether it is successful or not, the status numbers,
status message. Then there's details,
that is date server, and then this content
types of content type. Since in our case, in our programming,
we will send, send a simple text format. We will send a simple message, will not send the image
from the server to client. In response, we are mentioning their content
type to be text HTML, lipid was an image,
then it was different. He had We will be sending simply detects as a response
from server to client. That is the reason though. This header which
will be there and be sent from the server to
client, will be endoderm. The content type will be text, HTML, and the len, whatever data bytes
those sedimentary tending to decline in its bonds that we
have to mention here. Then a blank line that is a
little bit and this body, this body, we will be sending the message from server to
client so we need strain. You can pass you. You can
understand this is water. Those have always
send to the client. And then you will
get the page loaded. Then moving to the next thing. So here, it's all here, like in the previous session on this Linux operating system. When we have done
the communication for TCP server client, what, what will be required for
HTTP server client here, if you compare with the previous session met
and we have been thumbing holiness operating
system for TCP server line. There is no much difference
in this HTTP about digital communication
because he assembly, we have added the stolons. We have to give the message. If we send a message, it should be of this type. That is, it should be containing
the Hadean Haydn body. You can see it should
contain the header. This header. This is
the diagrammatic view. Like it looks like this. The version then the
status number of status message and
all of these details, content type, content, Lin, blank line and then body. So this we have to
write in us our code. So here we will be writing only the server code
while HTTP server, we don't need to write
the client code. While doing this or programming. Client only we have to give a
link on the router debts it and on the server side
you have to write this code and we have
to send this message. And farmer, I didn't body, which I have mentioned
in this diagram. When the service, This wants to climb, it should
mean this warmer. This is just a modification. If you have to achieve this
communication Institute, so good inclined, so you have
to add this message extra. What we will do so as compare to the earlier session
for TCP server client, what do you must drink line was simply sending a
message to the server. Here, what will happen? If you compare that program with this HTTP message to the
server in terms of URL. And then that will
be internally, it will be in terms
of header format, it should have covered
in the earlier session for understanding
the concept of this. Then that server ascend
then said about available. So send a message in a video dating the message from
the client site available. Also write the message
on the socket. So this is our
modification and what messages will be of this type? That is of this format. That is HTTP protocol
version density, this number, status numbers, status message, and
then content land, how much data it is
transferring from solar took line then the
content type where there's excess GM and then body. Then you can see
slash and that is a blank line, body and body. Yes. Hi, from whatever the
message is that whatever you are writing here
will be passed to the to the client in response. So this is an extra
thing that we'll be adding for the HTTP server or client if you compare with the previous programming
pollinates wherein the FDA, PCP several nine and
unrest all the boats. Same if you compared in which we have followed
in the previous session. Now let's start
programming ugliness using the C language like me to reach through the Linux
operating system. Unix operating systems. So I hope so you out I've
had on this dominance or we are simply moving to the
code I've already written. The code is a code for
HTTP. Just a second. Let me do things with gender. This is yard board
for STDEV server. Since I told you we
have to just write the code what side-by-side, not for the client
side, client-side, we're presumably give a link. That is, as I've mentioned, you end up with is
indigent $127 dot one, and the port number,
that is a 018. It will report the
client will report to the same local host
machine which I had in the server is running and the
same port number variable. So what is mine too?
Let me open this. As I told you, what
will be the difference? If you compare, if you've seen the Linux operating system, these header files via using
model socket programming. This is a main function
that is the entry to start an execution
of your program. All the things that
are repetitive, that is, again,
are in the Linux. I told you this socket function, which we will be
calling first of all, posts and argument will be
this Internet address family. Second argument stream data
that is a type of the socket. And third one, abnegation
group alright, equals 0. What it will return? It will return the socket
handle Let us server. And here it will be of type
and began case of Linux. This is what instructor light is used to fill the details
so that server again, what IP address and port number. So we had this, our
bodies buy into it too, particularly by IP address and port number
and this structure we can feel a bit back details IP address and port number. You have fairly here
in this three lines, you can see this one. Where are you calling
mine function? You're passing this
handle of the socket that we got here and we're
parsing this structure. And then we are calling
listen, listen. I've told you this is a socket, is a handle and this 0. That means how much number of line connection should
be in the waiting queue. So we don't want
any thing to read in the reading you
0 V harm done. You can multiply depending upon your requirement and
the order number it did with reasons we are doing X GTP recommended
communication board members. We have done so as mine
to this port number. So additionally, if you
talk about as GDP by HTTP, since I have told you this
message extremity will be sending from the server side
in our earlier session. Since we have covered what
TCP server and communication, only those boards that eating
whatever the client sense. So you can do any complication that was a chant communication
tool where you can also send from the sun
was from the server side. And you can also do read and
write on the client side, rectus, depending upon
your requirement. Here, we since whatever the client sends a
message to them, I will give a response to it. And this response, it
should be in terms of this header and body. So I explained you in the presentation on so and also the details
for hybrid and more. Do you can go through
the few session I heard before which I have covered understanding what is GDP,
several client communication. You can go through that session. That is common for
Windows and polynom. Here is the thing that
isn't sending the message, this message of God
initializing with this value. That is HTTP 1.1 does not know
status, number of status, message, then success
one on-demand content. How much length it is, 47 and then content
time there it is, it is a human. Then in slash and
there's a new line, there is a blank line, and then we're passing this message. But this is bass drum
server to client side. This message here,
what we earlier, when we reach here, then we
will send this message later. We'll send me like
simple connection from the client site files again the socket tangent and
then this structure. And then we get new, new socket handle, new
socket descriptor. So this socket descriptor that
is new will be engaged in read and write operation
with that on the line. Whereas the socket
individuals return here will be engaged in
connecting with that line. So this is what, and then those sad what
is reading whatever the lines and the message
that is it ascending or URL, that is one-to-many, $7.010 dot one and
the old numbers, so that link that is a local or the order with
them link it will be sending us a message will be converted in formal
paradata actually, and it will report, it will be passed
to the server and nephew and you will be
collecting here in number four, you can simply print
this buffer on the server side so you
will get all the data in formal credit which
clients and to server-1 me give the
link on the Firefox. But also then in gun versa, which will send a response. So you can see we have
written this extra code here. Compared to previous
code writing, we are calling the
right function from the silver side via parsing this descriptor
handle on the socket, this message actually and
when streamlined message, this message is the same
message which we have seen. There is this message, this message in descending from the server to
client in response. You can see that
therefore we are calling the right function
from the server-side, processing the socket
handle and this message. And then we are
checking for errors. This is warped how the
communication take place. So let us compile the code
and let us give a link on the browser or Firefox and see what will happen on
the server side. Let me post compiled score by, since we are writing the
code that would GCC HTTP server socket dot c. You can see here a dot out
is created, just run it. So you can see on
the top What's idea getting listening for
incoming connections. What is listening for
incoming connection? Now what we will do, we have to always post
launch our server. And then we have boo-boo that communications on
the client side, that is on the browser
here we'll use Firefox. I've hyperlinked $127 dot
one and the port number. And then in dentally, you added which the client we have done on the
application side, client-side, this
client will send a request to the sidewalk
informed saccades. So whatever descending
ominous will send a request to the
server that we will be reading from on the server. So you can see the message
printed on the server, what client is sending
in forms Al-Qaeda and the server will send a
message to the client. And you can see how the browser, the page will be loaded
with that message like whatsover sent in
response to decline. Let's see one-by-one. First, let me open that. You widen on Firefox on
the application site. You can see how this message game on the application side, on the client side,
water sidewalk center. Let's go back to the terminal and see what all things
got printed on both sides. So we can see here what happened post for so-called from
the server side we have or we have run this
server application. Run, we have R1, sorry, the server side, that is this. We got this message listening
for incoming connection. Then on the client
side we have given this link that is 127 dot one colon t. So nothing
was dead and the beach, it was just this mess. This link we have said, we have given on this Firefox, that is the application
side, client-side, this link, that is
from this message, God, god sent from client to
the server in formal credit. And then NACADA, we've got our rehab printed
on the server side. So you can see this is dark. This is the header
actually at nine states. This is all headed. This is a header which client? Client to the server. So that
is ahead of this format, that is the host user agent and exist and all
of these details. So if you have to
know this detail of what header response
from the client to the server menu give any link on this fight or false
but opposite. And you go to the
earlier session that is understanding sticky be a party server
client communication, you're going through
that session, but an unexplained knew what all header contains
from regresses and from client to site
and what response are wasn't true client in
terms of header and body. So you can go through
that session. I hope so you'll have
gone and you are going to sequentially going through
all of these sessions. This is what you
get from client, will end then in response
from the server side as we are sending the message
on the side of our code, we have written them and safe learning socket programming, so that is sent to the client. And this is what we see
learning socket programming. This is what we have done
with this communication. Http client communication. We have done in this
Linux operating system using C language reading you have to write on
either side of our board. Now. Thank you. I'm done for this session.
19. Socket Session12 Blocking non BlockingSockets MultiClientServer select 1stHalf: Hello friends. Today we will be seeing about blocking as well as
non-blocking sockets. What are the advantages
of using these sockets? As well as we'll be seeing
the usage of select. What this select and
what is its importance will be a ring these
things in art session as well as when we
seeing how to achieve multiline server
communication in Lena's using the C language. Let's start one-by-one. Blocking as well as the
non-blocking sockets. Blocking and non-blocking mode. In case of the socket. The socket can be either in the blocking mode or it
can mean non-blocking. More about the blocking mode post the default mode of the socket call
is blocking soul. In my training, I have explained you how
to create socket. We have seen that
when we find more of the socket which is
created will be the bucket. That means what,
what is blocking? Call that c. So suppose consider you are
calling function. So dy dt is yard blocking coal. Then you can perform that
read on your socket. Whenever the data is I'm in
the bill on your socket, then only be able to perform the read operation
from the socket. So in that case, if that is not a cop
isn't on the socket, what will happen if you're
calling a function? Obviously, it has
to wait for data to come on to the socket so that it can perform
the read operation. So this is men, it doesn't need to wait. Then you are making the
call blocking support. It is raping. It will wait till
the data comes onto the socket so that it can perform the read
operation successful. It is not returning immediately. It is about locking code. That means, suppose
in your program that I fight lines of
instructions and you're performing
some patients and in-between you're
calling a function. It will check whether the data is available
onto the socket. Yes, then it will read
from the socket and it will return at bedtime itself. But if there is no
data onto the socket, it will wait for the drug. So the moment this will block that operated
in your program. This is what about
the blocking code? So this is one of the
examples which I have explained you that is
about a blocking call. The example, the same example
that I have given you, which I have explained
you now in detail. That is, if you perform
the read knocking, it did not return until the beef as available on
the socket to be red. This is all about
the blocking mode. So let us see what
is non-blocking mode is single line nine definition. That is, these functions ridden immediately it in
the non-blocking mode, and you are calling
the read function. So what will happen if there
is no data on the socket? Still, it will not wait. It will return immediately, that is data, then it will read the data and will
return a dead time. Irrespective whether data
is present onto the socket. It functionalities,
it will not wait. Actually, there is no data, it will return immediately. This is when you make, your socket is
non-blocking mode. In that case, it will
return immediately without waiting for
an even to complete. This is our mold and
non-blocking mode. So you understood about the blocking mode and
non-blocking mode. Now let's see about how to achieve multiline
server communication. And this is how we'll cover
each and everything which we have stated in the
very first slide. How to achieve multi-cloud
server communication. So what we, what we are
doing, so as we know, the simple way to handle the multiplying
multiple clients is to simply spawned a new trick. But every new client
connected to the server, since we know that there is only one server and then
on multiple clients. So the doctor with
a single server, that it can be any
number of clients. So in case of the
multiple clients, the simple way we have
to do the communication between the server and
the client is what we do. We created thread for each new
client which is connected. So what can the problem
with this approach? Creating a new thread for
each and every client which tries to connect
with us over and we're one of the
problem can occur. Let's see the detail
in urine cell. This approach is not recommended because of the
below decide running gaits. The very first disadvantage
of creating the thread for each client
restraints to connect to server is, first of all, we know in case of the threats they are difficult to code, as well as debug, and sometimes they have
unpredictable results when all, this is all about the threat. Then this problem that, or what heads
reaching up contexts. So what does it mean? It means that suppose You are dealing with one thread and now you have to deal with another
thread at that time. So you'll have to switch from one thread to another
thread find x, so there is an overhead. So there is a time taken to switch from one
thread to another. So this is second disadvantage
of using the grid. The thought or disadvantages is that it is not scalable
for large number of plants or what
about if there are any number of lines
actually in that case, this will, this is not a visible way enough
to create a thread for each and every
client so that it will have a communication
between with this oval. And also the problem
comes on deadlock. Deadlock means whenever
multiple want to same loss, so many multiple threats wants the same lock at the same time. And that is the deadlock occurs. So this is on, these are the
disadvantages with using the threads on each plane communicates with the cell wall. So that is the reason
we know our goal for this approach of creating a thread for each
and every client. What is the next thing
which we can try actually to overcome
with this thread? While these disadvantages
operating the thread, the next thing is,
don't select con, to make a select calls. And what is this select Goal? What is its purpose
and the usage? Let's see each and everything in detail about the select call. And then later you
will be seeing how to Monica select call. And we will also see the
program and executed n. So better way to overcome with
this movie thread issue is by colleagues
select function. So let's see how the usage
of the select function. So we have to select
function a set of sockets that we
want to read from, depending on what the timeout
parameter s them, all. It when you're done almost
immediately with a set of those sockets are
ready to be read. What does it means? What does this definition means? What you will do? So there is a select function. You will be calling
a select function. So I'll explain you in detail
ahead how to make use of this select function will
be passing the setup, the sockets that we
won't be read from. So this is one on the exam
that so suppose you want to perform the read operation on different, different sockets. So you are having the list
actually model sockets on what all sockets are there
wherein you have to perform the read operation
on both sockets. So you will pass the list of those sockets and
not select function. As well as you will also
mention the timeout. What does this timeout about? This demo is like, suppose you describe some
time in this timeout. That time actually
the select function will be factory for our n will monitor all those of the sockets which you have given in the select function monitor. Till that time out. Whether between that
didn't get timeframe. Sockets have received
some data in any day, receive on any of those sockets which you have given in
this select function. Then it will return actually with all those sockets
which you mentioned, which is having their
data to be read. So this demo is given here till that homeworks climate
needs to wait. Suppose you are giving the
timeout of thirty-seconds. You are giving,
giving this socket actually in the select
function parsing tree. So all types of the sockets
wherein you want to perform a read operation and you have
given the timeout seconds. So within this party seconds, it will be 40 seconds,
maximum thirty-seconds. And it will see
actually which of these sockets is receiving
any date patent timeframe. More data is received
within that frame, then it will return. This timeout occurs. But in-between this time-out, before 30-second itself, some of the sockets
has received data, so it will return actually
when does time-out occurs, it will return with
all those sockets, which is heavy on that socket
so that it can be read. So I hope you understood
what I'm explain. Once it returns with all
those sockets which are having the data
present on the socket. In that case, you can
immediately perform an action. You can immediately
perform a read operation, since we know that
data is available on that socket so that time
you don't need to read. This is the purpose of
the select function. This is how we achieve soul. And the detail about this select function Omics
being here also. This is how to make the
detail how to use it. What all arguments this
select function is having. So far, It's tough. All we have VI as opposed
to load up the three sets. In this usage, I
have explained you only about the actual usage of the select is
weekend pass the three we can load
the three sets. One set will be for the other
set will be for the right, and analysis will be
for next section. So what is this sets? These are the sets, that means these are the file descriptors. You can simply say the sets means the list
stronger descriptors. You can clear the
list of descriptors wherein you have to perform
the read operation. Who can create the list of the descriptors you've had
and you have to perform the right operation and the list of descriptors
for the exception. So therefore room. Suppose you mentioned five
sockets actually descriptors list on the file
descriptors when you have to perform the
read operation, you have to monitor the read operation had been
in any of these pipe sockets, any one of them has to deceive
any two of them ordinance at any of them have received the date on it so
that you can perform. You don't preach in like read only the descript
leaders in this problem. Because you mentioned
that you have to perform the right
operation on the socket. And another part descriptor
set for the exception. If you will pass these, these three sets in
your select function, we will see in the
program itself, it will make you
how to use them. This is just a description
before starting the program, writing the program
and executing it, we're just looking
actually multiple things are required by you call
the select function. And it is a very important
factor in order to achieve a multi-line server
communication so as to a wider
decided one day. So creating a thread for each client connection
will act on the soul. These are the three things
which are required resets. The next thing what is
mentioning about the Select, it will test those
socket, It's whatever. So about sockets, you're
given these three sets. It will tell sockets and it will report back to you which one are
ready for those operations. That means whatever sets you mentioned give you
audit your Select function. These read, write an exception. So you are giving the list
of socket descriptors wherein you want to perform these operations and you
are also giving a timeout. It will see that die
within that timeout, if any of these sockets is
ready for read operation and the sockets which you have
mentioned in the descriptor set is ready for, right? Is ready for exceptions. So finally, the select function, we'll come back
with those sockets. I'm ready to perform
these operations. I hope so you understood this
point and this will make you more clear once we
start writing a program, then the next thing about
the select function is and that information, we can then process the
sockets that are ready yes, and ignore the rest of the time. What does it mean? It means that C, you are parsing some socket
list of the descriptors. Socket descriptor is to
perform read operation, say phi order of the socket. The socket descriptors
you are parsing, right operation and you are not passing anything
for the exception, suppose you are passing null. In that case. You are also mentioning that I'm
outside in one minute. Within that one minute, which all the
descriptors are ready. When I talk about ready, it means this is
a read operation. Then obviously there should
be a data on the socket. The socket, we'll be
ready to read it. The timeout which you
mentioned actually the lead time it will monitor actually
all those descriptors sets. I'm ready for read operation. We've got already
write operation, so it didn't each on them and it will return actually
information. So we talk about the same, then meant that
information we can then process the sockets information, which one is ready for read, write and all ends in both home the operation of them reading finally off
writing finally, so that is what it is saying. Process those that
already and ignore that. Let's draw and we have to ignore the rest of it's done already. By selectively
processing the sockets doesn't even never be blocked. So in this case we will
not be blocked because he has selectively selecting
only those sockets, which already the polar form. So we have to wait only
for the time is you have mentioned in there timeout in peace of the select function, we will see the detail till that time only you
need to wait actually, and whatever it gives
the descriptors which already you have to perform
the action on this. You have to go for it Actually and avoid using the thread, which is a great overhead using the thread which we have seen in the previous slide. Now, this is a node down to you, so that is a timeout parameter. So this is about
the select function on there is a demoed, but in case of the
select function by this demoed by diameter is required and select function. Is required to control the amount of time to
read for the action. Support socket ready
to be read onto. It means by the STI mode, by diameter is required
in the select function. It will just, it is required so that you have to wait
that amount of time. The descriptors which you
given your descriptor set, descriptor set
which you give it, you have to wait actually
till the timeout you haven't mentioned and
you have perceive if one of them are ready. Until that time you have, there is a reason to stay
mode this important. So this is how you control actually how much
amount of time you need to wait after this
time out gets. So what it will return
the list thrombus. The script knows which
one already quadratic, which one I already read
and all that details. Now, this is the
actual definition of the select function,
how to use them. So this is, this is just a
declaration here you can see int select and these
arguments are present here. So what is the
first and a human? You can see in the means it's
a datatype integer n MDS. Here I have described the
details we'll see here. As I told you to, descriptive sentences
are descriptor set for. That is FD set. This is the datatype actually
pointed type empty set. This descriptive satisfy
for reading purpose. This descriptive set is
for writing purpose, and this descriptive set
is one exception, purpose. And this is the
final timeout value which you have to give back to the how much amount of time it needs to read and indeed protect which of the descriptors from these sets actually are
ready for the operation. Now let us see one-by-one about these arguments
which you need to pass. Your data argument
details are there. So the first one is int and MDS, that is this one, MPS. So this is what actually, this is the highest number
file descriptor in any of these three set plus
11 value it will have. So this is first of all, since I'm explaining you, the Linux operating system, because selectors
used for the Linux, also it is used for
the Windows button. In case of the Linux
actually we will have this extra argument that
is NDF and NMDA is met in. It means actually what
value it will have. Since you had to
having this list of these descriptors for reading list of descriptors for IT. And let's bump this
script first exception. So in this one we'll be having a higher value plus one.
They'll give you this. And the NMDA is file descriptor. So what it is saying, the highest number of
the file descriptor in any of the three
sets plus mark. The usual thing that
you can only pass FD set size as the value
of this argument actually, because this macro will
give you the whole value that is large number of
descriptive said plus one. This is about this,
as I told you, this is for the Linux
operating system, this extra argument is there. But in case of the windows, this parameter is ignored. That is n HDFN NSAIDS.
Why does ignored? Because since these are
the descriptive sets, the set that is the datatype
FDI underscore sec. So in case of the windows, this FD set itself, then half of the sockets, as well as the
number of sockets. Actually. Therefore,
since this empty set in case of Windows is having
the details about number of the sockets and therefore
this argument that will be not that incase of them in those it is that
only in the Linux. Because in case of the Linux, only this value is
maintained because of the empty set actually, which we will see what
does this at least, and this is the data type
of the descriptive set. This will not have their
details of number of sockets. In case of Linux that
will just select function is having this
detail actually here. But in case of the windows
we can ignore this. Human is ignored because number of sockets are described
in every set actually. So this detail, we will see
a head. This is a defense. You would remember
that in case of the Linux, this is the argument, extra argument, but MBSR window, this is not present. I mean, back to that argument. So we are done with
the first argument. Let us see the another human. To human does every set pointer, the pointer to the center of the sockets to be
checked for readability. I'm seeing an option
in point though. So always remember,
it's not necessary that you have to
pass this value. Also, you have to
pass this value, you have to pass this
venue so it can, it is not compulsion actually. So it can happen actually, you are having with this value that is missed on this script goes which met and you have to monitor for the read operation. This value can be there, but this is not actually. And this is also melts and
this can happen actually. So even this can
be null actually. And you can have the value of the number of descriptors when you have people come
to light operation on, this is going to be null. These two things can
be there and this hot pink and therefore
they're the same. This is an optional thing. One of them should
be set actually. You cannot put them as none. So this is the thing. This is what an optional pointed to a set of sockets
to be checked for AWT, as I told the same thing
like this is what I think puppets and optional fat pointer to a set of the sockets
can be checked body. What list of the sockets which
you want to check, right? The ability again, exception, I know 10 it was setup sockets to be checked on
exceptional conditions. Very last argument
that is timeout. That is this structure, the pointer to it,
that is time o. What is the purpose of it? As I told you, the
maximum rate or null, or blocking or patient. Yet it is saying so suppose how much time you want to wait, actually the select function, I have to wait till that time. It will wait actually, and it will monitor
the descriptors. These descriptors
which you mentioned, you monitor for the
event to occur. That is, if it is,
we'll monitor for the read operation if it is
an ideal monitor port, right? If it is supported
me monitor popcorn. But till the time you have
mentioned in your timeout, once this timeout completed, it will return if there
is no till that time. If there are no descriptors
know sockets ready for annual dysfunction and it's demoed is or
what it will return. Null value. It will return saying that none
of them is ready, and then it will return. This is about that. But if you pass, if you're directly
don't give any value in case of the timeout you
just mentioned as null. That means it is saying
that it will simply be to actually keep on waiting if you pass this
menu as analytical, simply read any of
these descriptors, those sockets are ready
for any of the functions. So it can also be
indent, indefinite time, infinite time if there is no
data present on the socket, nothing to write on the socket, nothing, no such things. So it will keep on reading and reading if you pass
this value as null, but if you pass some
value and that time, till that time it
will get back to the and then it will timeout. But if you pass as null, it will keep on waiting. So this is what it
is saying here.
20. Socket Session12 Blocking non BlockingSockets MultiClientServer select 2ndHalf: Is what the details are about the select function
and what does it return? The same thing that is,
what does it return? So one auditory tone. What does it means?
The total number of sockets that are ready. So if it returns one
audit greater than one, that means how many number of soccer descriptors are ready? How many number of
sockets are ready? Actually, it will
give that value. If it returns 0, that
means the time limit has been expired and till that time no sockets
we are ready for. It returns minus one. That means an edit, a card swipe some
Edit Artboards, then it will return minus one. So these are the
things which it can return and this
is a possibility, but each of them, accordingly,
you can tell you. You can check in window, in Windows, in wind socket, this return value
will be socket. Use the applicable function
to identify the actual error. In case of the Windows, this will be of this type
socket and the squared error, this just to
distinguish between, this is one in which I'm describing and just
distinguish when didn't Windows I have
written extracting it in case all of the windows
this editor will be dead. In also you can call this
function w and say Get last error in order to get the details about the
edit, it returns an error. Okay, so this organ
understood editor in Windows. Now, to talk about the
details about this, every underscore sec, here we are using
completely a preset. You can see here this view WAS, is the datatype pointer to the MPI underscore
set this writer VS also datatype pointed are gonna underscore set also an exception
pointer to obesity. So what does this ever
be underscore sec, as I do on your desktop
file descriptors. Let's see details about it. Now. In case of the Unix, in case of the minutes
that is FD set, the other binary eddies. That is in case of
the wind, wind song. That means in case of
windows, these sockets, in case of the windows, this empty set means
the other structures. In case of Windows, dad
will contain the area of the sockets as well as the count of number
of the sockets, as I told you in
the previous slides actually that in case when
you call the select function, the first argument
is about this one. Nsaids wherein you will not
pass in case of the windows, this is not required because this just mentioned
number of the sockets since it is not
required in case of Windows disposed argument
because the reason this FD set, which is is it said we'll have, we'll have the structure
that contain the area of the sockets as well as it will contain the count of
number of sockets. So this parameter that
is number of sockets is already there in
this empty set in case of the windows
efforts not required. When you call this
select function. In case of the Linux, these are the sets will be
simply a binary arrays. That is, in case of Windows. It will be the structure that contain aerial sockets as well as they contain the count of
number of sockets and daddy. Good things when we present. This is the difference
between the unix and the windows in case
of Bordeaux and reset. And this is what
I mentioned here. That counter values this reason vibe in salt ignores the first
parameter of this select, which I told you that in case of Devin socket,
the first argument, which is that the
select is ignored, the does not require
because you're in a reset. It is mentioned under deep
stored in them he said, which I have explained,
you know, details. This line, these three
lines States stack. So now let's see more into the details for
these empty sets. These are the macros that I
used to work with these sets. So I am explaining you
all these things actually because I didn't really be writing the program using
the select function, which is very much
important as I told you, that in order to overcome with
this multithreaded atrial, we prefer using the select. We don't need to wait for a
long time for the timeout. Many we have to
read and it is very visible because it will
be meeting their time. And you can understand why
the definition it says, since we will be using all
these things in our program, the core writing a program. I'm explaining you
each and every argument in this slide itself. So that next thing when we
start writing the program, it will be very much Z. And these are not the moon balance before It's
starting the proof now. These are the microbes which are associated with the empty sets. These macro you will be coming across when you write a program, we will see I'm using
all these macros. So then you will come to
know if I'm explaining urine detail because
we are humans emitted, make use of it actually by
calling the select function. What does this empty set size which you will be using
with them resets. It is the value of this
macro is the maximum number of file descriptors that the empty set object
can pull in farming, in giving the
information about that. As I told you here itself, that This false argument in
select you what it will be. It will be maximum number of the descriptors from
these three descriptors, which one is having
maximum value plus one? This FD set size. That will completely give you
the details about this one. That is what? It will completely give
you a maximum number of file descriptors that the
empty set object can put. This is what about
the macro talks about in terms of empty sets. What more macro you can see with respect to a of the
sets F D underscore 0. So that means what? You are passing this empty set. This macro initializes the files a descriptive set,
two empty set. So you will simply initializing
your descriptive set to 0 and therefore you use
this macro FDA underscore 0 and E sets. These are the different
macros within the sets that are empty underscore
set B underscores. Let us CLR F, D underscore. It sets up a post-op, all these macros
which are there. The purpose of this empty
set is that you are adding this file descriptor
list of distributed. Since we know that
every set pointers set, it means it is having the list of descriptors,
soccer descriptors. And you want to calling this function and
you are drawing, you want to add this, could have gotten
this descriptor set. So that quarter then
you will call M-Pesa. In order to add this descriptor would invest list on
these descriptors. Focus on that and CLR, that means you have to clear actually this descriptive
which you mentioned. You have to simply
remove that descriptor, remove that sort descriptor
from this script. I said that is a reason
you are calling MPI underscore CLR code is sent. It means you have
to check whether this descriptive, which
you haven't mentioned, is it there isn't in this
descriptor set list on this descriptive know
the final inhuman of the select this timeout, this one, this one
select function. So let's see for that. This select will wait the specified amount of
time on details to arrive, and then it will finally give up and return with
the socket status. As I told you that, it will wait for the timeout. You mentioned
weight and monitor. Actually, if you have
given the script goes to monitor for reading or for some descriptors for
monitoring thought. It might be a post.
It will check all those descriptors which are vendor the radio or not till the time you have
mentioned in this demo. If not, then it will
behave accordingly. So here is two states that now note that the select port
return before the timeout. Embedded data, it's
only embarrassed no data than it will take for the entire time
before returning. Sort of seeing that once it
get the data returned to, even if you are mentioning
that I'm out to be 30 seconds. But if select is
getting some good, some of the sockets which
are Ready actually, in that case, it will not
wait for the whole time. Oh, I industry had
mentioned it can return before that
time get expired. But if there is no data, there are no activity
in any of the socket. It will read for the complete timeout value which to them, and they don't need States. Now if you said that
timeout to be 0, if you give them value to be 0. In that case, this select will return immediately
with this data. If you mentioned the zeros in their camo value in
the select function, the last argument who demands 0, and that means you
don't need to wait, you don't want to wait. You have to simply
return immediately. So it will simply check actually In simply call that select
function it proceed. Ritual. Descriptors are ready if not actually will not wait, actually simply did
not immediately. It means that if you send the demoed parameter
to the null, in that case, it will simply keep on waiting till it don't find
any event B occurred. In that case, it wouldn't
lead for independence, but I'm also, it can be, it can wait for infinite
time if there is no, nothing, no activity
actually, this node data. If you wanted to
add script presets for reading, if
you want to write, there is nothing you can no data to be right
on the socket. It will keep on
reading and reading. This is what venue it as a null. And if you extend the demo will be a
non-zero time milliliters. If you give some positive value, non-zero value, then the
Select that is not 0 value. So in that case it will
wait for the time which you have mentioned
and it will be blocking for death match among the timeout gets
over, it will return. This is what about timeout parameter in case
of dots select function. Now, what this timeout
have actually in detail. I mentioned that also
the timeout will have these things in
seconds and microseconds. This is just how to use them. Then the last thing that
is not non-blocking socket to achieve them
declines server communication. Instead of using the
select function, we can make the socket
as a non-blocking by following the
different function. What does this soul, as I told you that
there are two modes for the socket blocking as
well as non-blocking. So I hope you understood
about the blocking means it will read actually tell
the event will be occurring. For example, we have seen in
case of the red function, that if we are calling
the read function, if the socket as a
blocking socket, and if we add eating
actually in that case, if it won't get the data, it will simply read. The data is there on the socket. So in that case,
your whole program will be stuck because
you're calling a function and it
is still waiting for the data to come
on to the socket. The lead time your
program will be stopped. Talking, stopped. There'll
be have seen actually in this session that
the poster hall, in order to achieve the PICC
line segment communication, we create a thread for each plane which connects
actually to the server. This will be or what hurts
because of the disadvantages. It should be have
seen that board, to avoid those disadvantages, we are not preferring
using threat. We are calling the
select function. You have seen what is the
purpose of the select function. Immediate give the list of
descriptors which we want. Really monitor actually put
tilde the timeout value and it will return actually with the descriptors
which are ready, whichever department reading
which are ready for writing all those descriptors returns
were selected sockets, it will return actually which
are ready to be processed. This is how it will not read
actually for a long time. So this is how you are having a control actually on bathing. This is not one we
actually using the select. Another way is you lose, I'm making the socket
is non-blocking, so this is another thing to
achieve them and decline in several communication
and the details of how to use the
non-blocking socket. What is the purpose of
non-blocking socket? What will happen and how to achieve this month decline
server communication using non-blocking
socket we will be seeing in other session. You'll also see the program. So now I've explained you how the detail about
the select function, how to make use of it. And since we'll be writing
a program and executing it. So this knowledge
of select function, as well as what
arguments are required, details about that is necessary, there is a reason to
have carbon here. We will also see, then we want to see what about
the non-blocking socket, how we can achieve this Monday client-server
communication. And we will also write the
program for that also, Let's summarize what
all topics actually, let's see what our
topics we'll be covering in the next session. So first of all,
you'll be writing the program and executing it
using the select function. So this framing, this session is very much important
for you because in the next session I will be explaining you will
be writing a program on the Linux and we
will be executing it using the select function. Since more work on, I've explained in this
session would have been useful back in the day. You must see how
someone declines. Several communication
is achieved, we will execute it and we'll
see this communication happening on the Linux
in the next session. Next session will be
very much easy for you. If you have gone through this complete session
using the select function. Then the next thing
after that we will be covering what does
the non-blocking socket, how you can achieve declines
server communication. Then we will also see the difference between
these two approaches, which approaches the approaches for achieving multiline
server communication. That is the difference between the select function in
which I have shown you now. The difference between
the non-blocking socket, because this is also
the another way to achieve my declines
server communication. Once I complete this
non-blocking socket, we will see you on the
difference between them and which one we
are supposed to prefer. See which one is, which
one to use when either select a non-blocking socket that all leaders in
the next session. How to make a socket
is non-blocking all details and a
program and write a program and executed using non-blocking socket in order to achieve multi-cloud
and server communication. In the next Soviets
see on solvency the program using
the non-blocking, making the socket is non-blocking and executing
it on the Linux on, Thanks, We will be covering. So I hope you understood the complete session wherein we have seen all these details actually about the blocking and non-blocking sockets
that you've saved to select and how
to achieve them. Anticlines server
communication using select all the things we add via a v have gobbled actually
the next session, meaning see the program using
the select and see how to achieve this multi-line
server communication, writing the program and
executing it using C language. And thank you for now. Thanks alot friends.
21. Session13 Program&Execution UsingSelect MultiClientServerCommunication 1stHalf: Hello friends. Today we will be writing
the socket program using the select function in order to achieve magnetic lines
server communication, as well as we will be executing it on the Linux using
the C language. I hope so you've gone through the previous session and I have explained you the details, the necessity of using the select in order to achieve the multi
client-server communication. We have seen two achievement, the Client-Server Communication
at this first of all, it can go with the
approach that is creating the thread called each of the clients
connected to it though, there are multiple clients then multiple threads, we can see it. But what was the problem we have discussed in the
previous session? There are different, various
disadvantageous using creating the thread for each client which
connects to the severed. So I have covered
all the points, all the disadvantages,
and the audio session. It is not recommended to
create the thread for each client which tries
to connect to the server. And that is the reason we're not going for the approach
to create a thread. Instead of that, we will be
using the select function. So the details of the
select function lie. The select function is required. What is select function? How to call the select function? What all arguments you need to pass in the select function. All of the details I have provided in the
earlier session, and it is very much important in order achievement decline
severed communication. So let's see Just a short
description of the select here, and let's start
writing the program as well as executing
it on Linux. Just talking about
the select function. So what is the purpose
of the select function? It is, is to monitor
the number of the socket descriptor
sockets which you give in this select functioning. If you want to monitor the
sockets for reading purpose, if you want to
tell somebody that the sockets for,
I think purpose, who can give all the list of those descriptors in
this select function. And therefore this first-line
says the same thing. That is we have to
load up resets. That is read, write
an exception with the sockets we wanted
to socrates which you want to test for all these functionality we
can give this read will be the set list of the soccer descriptors
which you can give bought. I think, readability. You can give a list of the
socket descriptor for testing. And then there will be the descriptive seg
fault exception. So all the things details I have explained you in the
previous session, this is just a
short description. Then what? This select function,
then we'll return. So here we give all sort of a timeout parameter to
the select function. What is this timeout by
diameter I have described it is the timeframe within
which you have to test all the sockets. We have to test which of the sockets are ready
for readability. Which of the sockets are ready? Quarter-inch stability. So all those sockets actually
within their timeframe, which one of them are ready, it will return the list of those sockets if
the timeout gets expired and no sockets or
readability or repeatability. So it will not written
any of the sockets. So this is all about using
the select function. And if you have to go through the details to go through
the previous session, you will understand each and everything about the
select function. So let's start writing the program using this
select as well as executed Angelinos
using C language. Also friends, this
session which I'm giving you is the Windows
operating system. In order to write
the program and executed on the Linux
operating system, I had install the Oracle VM box. You can also do the same thing. It is very easy to
download and install it so that you can also try for different
operating system. And if you are having the
Linux operating system, you can directly write
the program with me and you can executed next. Often though, we embark
slits opened the Linux. Let's start the units operating
system and radio program. This is my terminal
of the Linux. I will tell you aware
of basic commands when you start writing the
program in the Linux. This is the pulling apart wherein I have in
the home folder, I have created this folio that is socket programming
Linux using select. Here, I have already
written this. Let me delete the output here. I've been in front of you
and then we will see, let me just open
this file. Let us. Socket several,
multiple client.read. So I've already
written this program. Let me open that and
I will pin that. Instead of writing each and 98 each line up instructions
from stocking, dismissal take lots of time. So I've already written the program and then
I'll explain you line-by-line instructions
which are used. Most of the things
which I will cover in this program I have already covered in
my previous session, I've explained, knew how to use the select function and
that is very much helpful. If you go through that
previous session, this session will be very much. So. I recommend you to go
to the previous session before starting This session. Start the server. So this is a sidebar
report tried to society. Once I explain each
line up instructions, then we will execute it. Once we execute the solver, solver will be launched. Then we'll be launching the
client from other terminal. So once we launch one client that will try
to connect to the server, then the client sends the
connection to the server. Server will accept
that connection and it will send an
acknowledgment message. With applying. That message will be printed on the console, on the client. You will see that how the sidewalk sends that
message to the client. So that red is the communication between both server as
well as the client. The second thing we
will be seeing in this program that
whatever we type, the message, the client, be echoed back to the client itself using the
select function. So if I type any
message, say hello, on, that message will appear, will appear on the client
console again saying hello. This is all using
the select function. We will see how the select
function works actually. And then if we try to
launch the second client, if we echo, this is another message on
that, on that line. Second client, it will be displayed on that
second line itself. So all these things we will
be covering in this way. We will also see how
the server talks to the client and if how we can echo the message on decline itself,
same plane itself, whatever message we
gave on the client, that message will be
appearing on red line itself on things we will be
covering in this session. In this program. I will explain you
what all things, what all instructions are required in order
to achieve this. So let's start set of the header files
which you need to false. Don't declare it before
starting the program. I hope so. You also gone through the previous setup sessions which I have covered
for socket programming. So you know, the B6, the socket. How does server communicates
with the client? What is the fungi
actually how server will bind to the port and how the client will connect
to the same port, and how this
communication is done. All the details I've explained stacking of the
session on this course. I will tell you how you ought to going step-by-step
sequence wise. Let's start. The Since this is a C language, but execution of your program always starts from
the mean function. So this is our main function
that I've done the code, this select function
so far, support. This is the main function. These are the Declaration's
which I have made. So let's see one by one. You can see this variable is there which I
have initializes. Do we see all of these
things that it is required? So this is the, this is, these are the variables
that is master socket. This ADD LN line
underscore sock. Then you can see an array
on the client socket that is having n elements in it. This variable max Klein's, which is having, which is
initialized with the value ten. Then all these
variables which are, which I have declared. I will explain you what is the purpose of
each variable months we start with the line-by-line
instruction explanation. I'll explain you what
is the purpose of each and every media
abilities declared? Variable max underscore
estimators of the data type int. This is maximum or this could have those file
descriptors which are dead. In the previous session.
Also, I have mentioned you that about the details of
the Avy underscore sec. So again, the school
said actually, you know that there are three sets of FDI
underscore cell, that is for reading, for writing and for exception. So what value of this
maximum and Steve will have it will
have the maximum. Which three of them is
having the maximum value. You can see here
the structure that is obedient been
named as address, which is of the type structure
sock, DDR, and the school. I hope so you are aware
of this structure. This is the structure
socket wherein we have fulfilled both elements
with the details. The third one will
try to bind to that. We have to give the port number, we have to give the address
family around socket. So all the details about
the socket API already in very starting
session of the course. So please go through it. We will be covering,
the main focus will be how to use the select function in the socket
communication board. Every communication between molecular and
cellular communication. So let's see. We are
using a buffer actually, so we will see how
to make use of it. I heard. And you can see FD set. So we are using
on the side here, since we are in our
program, monitor though, descript sockets for
reading, writing, you can give also called
writing depending upon your requirement
here I have given only boy getting,
let's talk them. I will process. So here I have taken read FDA
surface of the data type. Again, this code set,
you can see here. Though, get a point.
The message that is, this is a message that
will be sending from the sidebar to nine drives
to connect to the server. We would send this
message from this, I will run this program itself. You'll see how to make
use of this message, August send this message. Then in this three
lines of instructions, you can see what
we're doing here. You can see it is a for-loop. And here we are taking
the loop starting from 0 value, max underscore lines. What does this make sense? Cool clients, it is
initialized to ten. So since I want ten clients, can brings him ten clients
can connect to the server, so I've given it as ten. And therefore this new, and therefore this loop
will iterate from 0 to n. Initially, what I'm
doing is that what is this area about client socket? It is an array of these
soccer descriptors. So we know that once
the socket is fine, socket is created, then it will return a socket descriptor. We had maintaining the
socket descriptor in this adding named as client
and the school soccer. And initially it, since there is no client connected,
that would be, we'll initialize all
ten socket descriptors of the client will be 0. Once the client tries to
connect to the side of it, then one-by-one, this add
elements will be filled. Socket, it's going
to pull it off the client which
tries to connect. So you'll see how deep on these things in this
entire program itself. Then what we are doing. Since this is a
sidebar o program, we will create the socket
on the side-by-side. What is how to
create the socket? We know that we have to simply the socket
function in this manner. And these are the setup on humans which we are
supposed to pause. That is this first argument, second argument, and
this part argument. This is the address family. We have seen the details
about it in earlier session, the type of the sockets, and we will do the socket communication using the stream socket market Bagram. So I've mentioned the
type of the socket also the details of this unexplained
in the starting session. This 0 will be passed here. Once the socket on the server-side is
created, it will return. If it is successful, it will return this
master socket. Check actually whether
it is successful or not, definitely this condition
is given like this. Here this master socket will be the socket descriptor on
the sidebar, which we got. Once this socket gets
created, this master socket, we will try to bind this master circulated server socket
to the port number, and we will try to
listen on port number. I will try to simply
accept the connection. If we tried to launch the client from other
side from an N-terminal, then once it, once
it is listening, the server accept the
connection from the client. If the client connects
to the same port, numb to all the things we will see here on the server site. How to bind, how to
listen, how to accept. Now the next setup instructions, which is there, is
set socket of OPT. So this is also optionally and the master socket to allow
them ethically connection. So it gives the
different options you can give off the socket here in this instruction
that is done. Next sector of instructions
which you are getting, you know, you can see it. This what you are
doing as I told you, what does this address? It is the arteries of the
socket Soviet already seen in the basics of the
socket. How to fill. This is how this outer
pillar, this variable, each elements of this
variable one-by-one, with the board member
of the family. And with all these things
we have to protect. The destructor is
not a member of. So all it is having
these all members in this video bill is having that is the family
we have to live with. Family of the socket. You want Ben? That all the details of the socket time explain you
in the starting session, please go through it also, I have focused on this
iron ADR and the score. In the earlier session of the socket to please
go through it. Then this port number, which I will give
you a sport number, I have simply hash
define it to four times eight so you can define number to any of the
report number, no problem. But this remember when you try to connect from the client, you have to connect on the same port number
of the sidebar, which will give
you, if you give me a different port number,
the server site. And you want to, and
you want the client to connect to give the
same port number, whatever you give here
on the server side. So that decline then can decide what then can
accept the connection. It is binded to
that port number. So this is how we are binding the sideway socket
port number and we are giving the details of the
list family pocket for me. So this is all about
besides program. Just simply printing the message listening on the port number. So you will get this display
message on the console of the sudden elements we tried
to launch their cyber. And then here we get, we have to call the
listen function. That means how much of the
pending connection can be dead on divided socket two of the client depending
connection V1. So therefore we are giving
this listeners too. So you can give any number
of pending connections on the client depending
upon your requirement. Then the next thing which
we are doing is that we're simply printing this message on the console waiting
for connection. The server is waiting
for connection. All these message we will see on the server site since this program is for
the silver site. And then you can see
here we are taking a loop that is the high loop
and we're making it as true. So you can understand
if we take a loop and then this loop will
keep on iterating, then you don't return
somewhere in your blog. You have to, in order to just
avoid the infinite loop, you have to return from this doctor depending upon your requirements and
you have to return. You have to mention that
this is a loop which will keep on running
continuously. So here we see what
we are doing exactly. So you can see these
instructions which we are given, that is FDE underscore 0 again, VSCO set up all of these things I have explained
you in my previous session. These things are extra and
you use select function. So always remember whenever you are using a select function, you are supposed to use all these equalities
functions and you have to initialize all of these
things in the same manner. This is the details about it I've given you in
the previous session. What is the purpose of
the FDA underscore 0? Since we are simply
using the read f ds, we want the software to monitor on the board
reading purpose. So initially we have to
always initialize it to 0. And therefore we are calling
this AVG underscore 0. So this is what this one which I
have declared and startup you start off our program. So you can see here only
taking one every said we are. So all these things
we will be requiring and we call the select function. In Italy, we simply
neutralizing all the lists, list of all the evidence to 0. This means that if you
call this function, then f decide which is, which, which is the time calling here and parsing
the Moscow socket. And what? This function, this function, if
you call a reset, it means that whatever
socket descriptor you give here actually that
will be added in this list. Socket descriptor. So this is the particular individual socket descriptor
issue one puts it. So suppose you have to monitor
three socket descriptors. You have the goal three times, both have the underscore set. In the first argument, you have to pass that
socket descriptor and you have to add
that socket descriptor. You have to add in this list of the socket descriptor that is read FDA since
you want to monitor that socket descriptor
for readability. And therefore you are
passing that said TO. So suppose you wanted the socket descriptor to
monitor for writing purpose. And if you have
initially or declared right FBS that you give the socket descriptor as opposed argument
and you can give as a second argument the right
MVS address or write f ds. But since in this
program we want or need to monitor socket
descriptor for reading purpose. And therefore, I have given, I have to add this
socket to this list of the socket descriptor so
that the server socket can be monitored for
readability purpose. For that what I'm
calling this function. Then what I'm doing. You can see here Max, as I've already explained you, that we are letting
this max as SB. In this way, as d at the
starting of this program. What is the purpose of it? What does this cell
video will have? It will have maximum of
the socket descriptor set. He said from this socket
descriptor as we are having actually on me one
socket descriptor here. We are not creating 23 socket descriptor
equitably have dust, mask the sockets or whatever row socket descriptor is there. So since we got
though, we create, till now we have created
only one socket and it return Burma set of
us socket descriptor. So we will mention this. We will initialize
this max as David, that value, that is redact variable master
underscore socket. Then we're simply printing
the message here is to get this master socket we'll have depends on whether you
have to print it or not. This for-loop I have taken. So what is the purpose
of this for-loop? So you can see here already
that is a while loop. So inside this while
loop, first of all, we have to initialize
all these things. Respect to this deed FDA's. And then this is a for-loop. Again. In this for-loop, what I'm doing
exactly post-op on. You can see here at the
starting of this sub y loop, I am simply adding the server, a socket to the till that time you can understand
only one socket descriptor. I haven't added in bed
descriptive set of the reader to monitor
for auditing purposes. But I also want a
list of the lines to be added to the
socket descriptor. Descriptor set in order to
monitor for auditing purposes. Because if suppose something
is passed on the client and in that case I
have to also monitor, actually, I had wanted to read actually from
the client socket. I want the client socket
also to be monitored if there is some activity
going on and stopping. Till now only the master
server socket is monitored for reading purpose if
I have to add all and clients actually
act on Monica, any action of reading is
to be done on hindsight. I can also add those clients
sockets onto this rate of BSL so that things should be
read on that client socket. Then I can read it
actually once I add actually using the empty set. So first if you want to monitor, you have to also add the client, the client's sockets to
this quantity in purpose. So you can see here
there is a reason I've taken this for-loop here. This for-loop is that
Isaac equal to 0 I less than max underscore
clients and then I plus, plus max clients, I have
hard-coded value ten. This is desktop display message. Now you can see just
this client socket. As I told you, this is a
list of this area is used to maintain the area of the
client socket descriptor. So initially we have seen, we have initialized all dance off the client descriptors to 0 because since we don't have any client to an active,
actually one by one. As soon as the client gets
connected to the server, each element will be filled. Actually, this area
element will be filled with that socket
descriptor it off the client. Therefore, initially
you can see here, I'm taking though, I'm retrieving the value of
this or this client socket. Since when I is equal to 0, line socket area of zeros will
be as G will be 0 itself. Because since still now
no client is connected. And there could have
checked this condition. Condition is that if this
socket SDS greater than 0, then only you are
supposed to add this client socket descriptor
in earlier videos. So what does this three line
of instruction all about? Simply, it is all about that. I'm just checking
in this for-loop whether my any
client is connected. Since I told you that. If the client is connected, in that case, what will happen? We will try to fill this area with that socket
descriptor of the client. So suppose only one client
is connecting to the server. So I will get the socket
descriptor on the client and I will fill in this
Eddie, Eddie zeros, then second client I tried to connect to the
server and then get the different socket
descriptor of the second client at
every typo on this. Actually, since in each allele there are no clients connected, you check the conditions. Obviously that is more
connected and echo this SD or 0 will be 0 itself. And therefore this
condition will not be satisfied in their code. I will not add the
socket descriptor, although he'd have months
decline and x to the server, then only direct
line we can add to this reader VS2 monitor
for auditing purposes. Initially, you can see here not this condition
will be not satisfied. As well as this is
one more condition. That is, if SDS
greater than maxes, you didn't know yet
having Max SD is what actually it is though,
server socket descriptor. I'm checking actually if this
11 is greater than that. So obviously till
now we don't have any climb and active record. This condition will
also not be satisfied. Just this will be not satisfied. So we don't, we won't have
this instruction executed. The for-loop thumb IV will
be getting implemented. It will become one for
applying socket one. You can see, since there are no clients
sockets connected, therefore this value
will be again 0, and therefore this condition
will not be satisfied. So this will simply, this iteration will happen from Isaac while to 0 I less than. Then because we have initialized
max client to be ten. Since at this starting point, since no client is
connected on and starting of this
program itself PM initialized all client
though descriptors to be 0. And therefore, every time these two things will
not be satisfied. And therefore, no, none of this ocher descriptors will
be added and descriptors will be added on to the descriptive set since we don't have any
client connected, therefore, their area element
is not fitted actually, we are not having any socket
descriptives for that line. So this is at the starting time, this will be executed. So each time the
loop goes actually, then you can see since this is a vital
each time this military, each time this loop, again, this will be executed.
22. Session13 Program&Execution Select MultiClientServerComm 2ndHalf Part1: Then the next line of
instruction is selected. This is a very much important
though instruction. So what will happen? Now? We are calling the
select function. We are passing all
these arguments. But one disposed
argument will have. So the details of how to call the select function and
what arguments did inside, they're all covered in
the previous session. Please go through it first, as I mentioned you maybe to disclaim as the first
argument will have maximum on those
socket descriptor set above the three
descriptor set plus one, this descriptive side,
side eight MDS, right? Yes. And exception. And he has said, so which of them is having
the highest value plus one? Since this Max has dv. Now only one socket
descriptor is there. So its value, whatever the master server socket
descriptor is bad, which will be gone after calling the socket function at value
plus one, that would be bad. We have to ask this in case
of the Linux operating system that all that also I
have described to you. In case of the Windows
operating system and you call the
select function. This is not given actually, I have also explain you why. Because this parameter
is included in the school said So
all the things are covered and don't
give a session. Please go through it. Then. You can see here
the second argument, we're passing it as
address operator VSO. We know till now we simply
adding on Yvonne socket descriptor industry their ideas and that is on a server
socket descriptor, but none of the client
socket descriptor we are adding know
currently at this stage, even see later
actually as soon as the program gets executed, as soon as we tried to launch deadline scenario of
exchange actually then we will back client on the client socket descriptor
me lead on this video. For now, since no client
connected or not, There's no question to add
the M&M in this later. On, the one socket
that is server socket descriptor is
added in this video. And this value, what is
this called argument? We know that this is
one. This is empty set. This is for writing purpose. This is what exception purpose, and this is a timeout value. So all things have gone
in previous session. This we're passing as
none for writing office because for now we don't
want to monitor for writing. If you want action, you can also modify it in your, you know, as I told, you can add a quarter, right? And release and whatever. Socrates, if you
want, you can add it. You know how to edit. I have explained you heard this. You can modify your code depending on the
requirement for my case. I want to monitor for
auditing and therefore, I'm not I'm parsing this. I'm passing for writing IS null and the thought are human. And this fourth argument
here is one exception. I'm doing with them
to monitor for exception if I'm passing it as the last argument
is the timeout value. I will also explain new detail actually
what timeout value, if it is a non-zero value, that means that much amount of the time it will monitor
that actually perceive it off the socket descriptors
and this need of VS is already reading public. So since venue give
the value is null, that means you are, you have to. This, this select function
will keep on waiting. Actually put an activity to
occur on the master socket. It will not return any DWT, any detection on
this master socket. This is depending upon what value you give
to the timeout. So all dynamic explain you
in a previous session. So if you give a non-zero value to give some definite
time like ten seconds, 30 seconds till
next time it will actually record and activity
have a code on the sidewalk. And if not, then it
will return what? And if we didn't have time, if some activity opposed, then it will return the
index socket descriptor. And you can perform the
operation of breeding. Depends, sorry, that means
you are having the control on the select function depending upon this value of the timeout, it will control
the homeless time. You want your select tool. This is controllable, so that is the reason
this is in one day. So parallelly you can process
with other tasks also. So it will not keep your original function blocking for a long time, poly-time, you had mentioned that
much amount of time it will be blogged
as it will be wrong. Medium with processing under
task after this timeout. Then this is one
more row message which will greatly
increase up to select. This just do explain
you the floor. And he obviously see
here how the flow goes. Now, we're checking with the additive some
deselect, it will return. This is a return, actually
it will return some value, so we are checking it actually. If it is less than 0, awesome. In this manner, then we
are printing the error. We are checking into
some metal have occurred by calling
the select function. Always. Since bought. Now, at this stage. And having only one
side of a socket, we are monitoring that if some action is performed
on the server socket. So you can understand
actually what action can be performed on the
sidebar socket of Besley. Till now, what we are
done, what we bought, we are achieved what we
have done in According, we are simply binding. We have done with binding the sidebar socket to the port number and
we are done bid them. It is listening actually. And once it, what
activity can occur on that server socket
activity can occur like we are trying to
learn launch deadline. So obviously that nine will, if I try to connect to the sidebar and then
servant have to accept it. So that is the activity that is accepting the
connection of the client. That is one activity
which mechanic ocher on the side of eye socket. So in that case actually got
server socket will become active because of client will send an action to
sidewards sort. In that case, the sidebar
will become active. And since you aren't already monitoring your server
for reading purpose, Deco, you have to check
actually with these options. This option via it is required. I've also explained, you
can see this block I have done after the
select function. We have cool setup instructions to check actually either any of the soccer
descriptors has been set actually in your descriptor
set. It means what? Since what select
function will return, actually it will return
with that number on top. And this could have something
descriptors with the ID for the operation to perform best when you have to
keep on ticking actually, which are the socket
descriptor is ready. So also remember this
read f ds will get modified actually after
the select function. So since been, since now
you are passing just adding only one socket is
gonna let indeed obvious menu select function. This will be modified with the value of the
soccer descriptors. Return. Yes. So this block is
there in teaching only till this much
why this is required. This block, which I've
just highlighted here, it simply says that after the select function
has been called, obviously when it
is returning to see that the dead descriptor
set in your rate of lessons I told you the state
of VS will be modified after you call the select function initially what this
rate of VSS having, having the list of both socket
descriptor is with you. You want them monitored. In case of the read FDA's, you are adding all those in
your creativity as well. Once this select function
has been called executed, it will return right? After it return, this
will be modified. This will have with
that on the list of descriptors which are ready
for that functionality. It will not have the
oldest socket descriptor. It will have only those
socket descriptors are ready in order to perform the reading purpose in case
of this descriptive set. And therefore you have to
lose this highlighted thing, these instructions in order
to check actually walk or socket descriptor
as you are given the WSUP check one by one. But either socket descriptor is present in this reader of ds. If it is present in this video, that means that socket
descriptor is dead. Socket is ready for
reading purpose because this after select modulus quantities
will be modified. Disability return will
have the value of those only socket a retarded,
ready coordinating purpose. If it is having n
socket descriptor, which you are monitoring for reiterate read and only
two of them is ready. So the select
function is called. Only two of the
socket will be added. Read FDA's and you don't know. You have to check one by one. All of the ten actually, if you want to check
which of them is present in your descriptor set. And obviously two of them is that condition to
this since in our case on the bottom now this is IVR monitoring only the
master server socket. And therefore I'm simply, I think the code for taking
many semesters, etc. eye socket descriptor
it at his master socket is present in 3D of ds. If it is present, that means this socket is ready
for grading purpose. This condition
will be satisfied. This is the main purpose of using the FDA
underscore is said, You are supposed to use after the select
function is called. And therefore in this cell, if this is satisfied, it is gets satisfied. That means I will call the
exit function I told you assign connecting
to the server on the same port number and then those ever need to
accept that connection. I put. I'm calling this
excerpt function. And then five, seeing the master Socrates
want it is a server socket is we're parsing
the details that is in-person address
and all these things. But I mean it does,
is it returns, it will return the
socket descriptor of book line, which
gets connected. We got this stage. This condition is satisfied. That means at this
stage there is one line which is launched. So till now we didn't have any. But once we tried to
launch dark line, client tries to connect
to the solver in bed is after this select.
The select function. You know, it will be waiting
actually in our case, it will be waiting for indifferent night time till it gets a connection
from the client. You can see here, I'm printing this before select when you
launch the server. And you can see here,
you will get the message before select this point. Those server is
waiting actually, since he had mentioned here. That is this, all these things would not
be satisfied actually, that one's not lying because
this condition is only when the client tries to connect to the server
and there is some activity. The lake I in descending
the connection, then only we are. This condition wouldn't
have satisfied if this is the thing. So definitely you can see here, once I tried to launch
the server on New, you can see the local
select default select. You will not see the log of this select because a sudden
that is waiting actually, because you haven't given here. Once we launch dark line, it will try to connect with
the solvent and you will get all this message
will be printed. And also you will get
this message to be printed at this new connection. Actually that means applying got an in afforded the
same new connection. This video will get only
one client gets connected. Then obviously when client
is getting connected, then server is sending the
message. What is this client? So this is the socket descriptor or the client which
brought connected. Since this excerpt
function will return it, return dark line socket descriptor from the server
side we're sending. You have to sand on this
socket some message, as I told you, what is the
purpose of this program? What we will do, we will
try to launch server then readwrite to connect on the same port number
from the plain sight. Then it will. This all things will be
appearing that is on low displaced IV will
get in the server side. You'll get this message, new connection on all. The server will send a message to the client in this manner. This message, what it is there. Now, the use of
this message comes. So since I'm already recorded
this message to this value, you can see here, this is
a cat pointer message. And I'm given this message is acknowledged acknowledgment message
sent from the server. So here we are sending
the message on the client side in this
manner, the client socket. And this is just to display
message on the server side, acknowledgment message sends
successfully from them. Several. Now, this is one more than loop actually, this
condition itself. So all these things
where I am mentioning it actually when I read these instructions as
given in this condition, this is the condition and
you gotta master socket, that is vendors our Socrates getting the connection
from the client. That means the client
is present actually n. Now, obviously what
you are doing, you are trying to exit the connection
from the server side. And one more thing you are supposed to do, you
can just guess. The more thing which is
required is still now. You can see in our program
what we have done. We have in the array for the
client socket descriptor, initially it is
onset to initialized to 0 because there's
no applying connected. But now at this point, if this condition is satisfied, that means it is accepting the connection back then it
can accept the connection. And there is a client request actually to connect
to the server, then the server can
accept that connection. That means there is a client
which has been launched. Now what is our role actually, what we are supposed to do, we are supposed to
add that client actually in the descriptor
set for reading purpose. That father in filter is something happens on
that client socket. For reading, we can simply monitor actually and we
can perform the action. So therefore, this logic is required actually here you can see this loop and you can see I'm taking a loop
from starting from 0, I less than max underscore
line I plus, plus. I'm checking this
condition. Actually. Why this condition is checked, because you can see initially all of the area and humans of this client socket is
initialized to 0, I suppose. So initially we know that
none of them get launched. Now at this 0.1 on decline has been launched and only
one client is connected. Therefore, you simply fill that socket descriptor
of the one line. This you'll fill it as
a zeroeth member of this area of the client socket. This is having the list of
the nine socket descriptor. So only 0th element
of this array, this client socket
descriptor will be filled with the supplier and socket
descriptor which you bought. The inside would
accept the connection. Why this condition is required, for example, for now, since what we're
doing each time when the client gets
connected to the server, we are adding it on the socket of this
client socket here. And therefore, in
that case this, since first-time we
have already added it. It is here. And second time, again, the connection comes on. Another client tries to
connect to the server. What will happen this
obviously the 0th element of this array will be
non-zero because you are, you are already filling
and bedtime itself, the client socket
descriptor in this setting. Therefore, this condition
cannot be satisfied actually, and before I will
become one, again, your client socket manual
check if it is 078 will be 0. Simply to say this client
socket I will be 0 only when your check actually begin
that it will try to add. So I hope you are understanding actually
what we're trying to do. So one by one each
time we will try to fill this array by simply
checking if it is 0. Actually, that means we have that client socket descriptor
at that position itself. If it is already
having some value, that means that our
socket descriptor is already added
at that position. We are to increment
I by one actually, and we have biotech
other position whether that value is 0 or not, it is break Maya applied again, we don't need to take
actually because we got to the point
where we have to build this socket is client socket
descriptor in the array, and therefore we
have to come out. And that point.
23. Session13 Program&Execution Select MultiClientServerComm 2ndHalf Part2: The now, the next instruction
will be executed actually because all these
instructions which are present in your while, true, while true,
which we have given. Here. This is a whole block of the
code is present actually. Therefore, the next instructions which will be there actually
that is outside this. So every set. Now this FD set, we have seen what all
things was present. Actually, what we
are supposed to do, I stop all you have to
accept the connection from the client and the client
socket which we get, we have to simply added
in not Eddie actually on this client socket does
this activity we have to do. And we also sending
the message longer to decline these
things we are doing action extract to the
outside this if condition. That is one more for-loop. Actually, I didn't know. This is in general the
Khonsu, what we are doing. This for loop is
simply used to check, actually read that whether there is any operations on line. Now you know that
your client has been launched actually this is
connected to the server. Now you can add actually
your client actually onto the descriptor set
for reading purpose. As well as you can
simply check actually the same thing which you are checking for
the Savoir side, that is a v is equal to set
after the select function. That's the same thing
you can check actually pod Also the client
socket actually. Now this for-loop actually
is just it used to check the one that
actually if there is some activity are
input-output operation going, if there is some IO operations going on onto the
client sockets. For now we are having
only one client socket, but now at this
point we are not, we have still not added
that client socket in their descriptor set of the read up ds so we
cannot monitor it, right? So that, that thing is spending Olivia to add
that client socket also in the MDS actually even see the
head we have to add. Just remember by
this for-loop is used actually this for
loop is just used. It can see here, I've
taken I is equal to 0, I less than max clients, or now we are
having ten clients. Actually makes him a mechanic. Lines can be there.
That is that now this client socket of zeros
in Italy I is equal to 0. Applying socket in this course, OK, and z to what it is. Yet only where you can see one's deadline what
connected to the server. We add filling this socket
descriptor of that client in the 0th element on the client socket
restaurant barrier and humans offline socket is 0. And therefore you can see your client underscore socket of the subscript 0
will give you though. Good descriptor of the
first client which drive, which is authentic did
actually to the solver. And therefore you are having the SD do some value actually. And therefore in that
case, so this is what, when this all goes on the menu or trying
to launch the line, not when you tonight for
launch only the server when replied to launch the client and connect to the same pole, then only all these
things will happen, the n Then we're also
checking actually, that is, if the client is connected to the
socket and this SDK will be having some
value, it will not be 0. In that case, actually, we are just checking
the condition actually. And D is said is what it is
outlined socket actually descriptive if it is resident
in this read every year. So when this function call him on neutral check
after the select only, we can use this function
at a Soviet and checking whether the client socket
is present in this city, the MDS effort is not present. That means this
socket descriptor is ready for reading purpose. If it is present, that means
there is some activity on this client socket for the reading purpose
and we have to perform the action,
we have to read it. This is what the
initially nothing will be satisfied at this condition
because first of all, we're not adding actually, we have not still added it as
d Actually in this video of this in order to monitor so that we can check after
the select function. So this will be not executed. So even if this for loop gets
executed till this point, since initially your client
socket is having some value, this message will be printed by this condition will not be satisfied because we
are not adding this. We're not adding the socket is the client socket descriptor. Indeed FDA's, this condition
will not be satisfied. So again, what will happen? Which condition is this is whole complete conditional
node with this whole complete if condition
will not be satisfied. Then what will happen? Again, the for-loop will
be incremented by one. Again, we will check this condition if it is
less than my client, then again client socket of one as d. So now as d will
be 0 because we are having only the 0th
element of this array to be having the first socket descriptor of
the course client, but the client socket of mn is nothing actually only
one client got connected. Actually, this will
be 0 acted this for-loop actually it
will iterate till ten times because this value
you have given as ten, this will iterate ten times. Do you can also apply a break? If this value actually
it is 0 actually, you can simply apply a break. You can add that code
also in order to avoid unnecessary
iteration of the for loop. Now, then what will happen? Actually, once this one loop has been iterated completely, then the control
will again go to the first line on this while loop because
you have given while true. Therefore, it will keep on iterating until an
analyst you don't return. So again, the control
go here actually. Now again, what will happen? Always remember one thing. By this thing. This thing is I have
given the starting of the while loop because
you have to always initialize your editor
or read a VS with 0 value because you know that
after the select function, this dy dt ds gets modified with those descriptors
which are ready for reading purpose or sense. It is more or modified after the calling
the select function. Therefore, every time then this control comes
at the starting of this while loop and
you have to again check actually the same thing. You have to always clear it
actually so that you will not get the value on
the earlier value. Therefore, your 12 is set it to 0 at the starting point
of this while loop, and then you are setting. So here what will happen? Again, this soul master
socket is already there. This will be at, since
you are clearing, the speed of B is. Then again, you are adding this sort of eye socket to this Vds because you
are, you have cleared it. And then this maximum is
D will be the smudge. Now what will happen? Let's see how the
things will go. We are considering that
though we are connecting one client is connecting to the server on the
same port number. So we are considering we
are having one client. Now if you consider that in
that case, what will happen? Again, this for loop
will be executed. So this is, you can see line-by-line
instructions is executed. So what instruction is next? It is a for-loop iterating
iss equal to 0 till I less than ten is equal to 0, therefore client socket or 0. What? We know that since one client is already
connected, therefore, we are able to sort field
actually the 0th element of the client socket with the socket descriptor
of the first client. Therefore, this will
return a non-zero value. This will have positive
value, it will not be 0. And therefore this
condition that is greater than 0 years, this condition
would be satisfied. And yard is the point
where you are adding your client socket in the red
disk, read descriptive sec. All right, I hope so. The logic actually, there were no client actually I told
you that initially we, we're initializing on the
client socket descriptor to 0. Actually we have seen in Verdi, but that debt point when this instruction
we had executed, we'd have seen since all of
the array elements are 0, and therefore, this
will not be satisfied. We have seen, but
now since we are considering one
client is connected. And therefore when this
instruction gets executed, the 0th element of the array is having the descriptor
set of the first client. And therefore this will
be non-zero value. And therefore this,
that means you are having one client
actually which you are supposed to add
the descriptor set and therefore you are calling. And we said, and
this descriptor set, this descriptor that is
client socket descriptor, that is SD you are adding
in this list of lead. Now what do you have indeed FDA's posture while
you are having this sort of a socket that
is master and his co socket. And you are also having your client you are
considering is connected, therefore you are having
this socket descriptor of that client in this read of Deus to socket term descriptors you are having now what
you are doing here, you are checking whether debt socket as D is greater
than max as the sole. Initially your max as d was
the master underscore socket. Now you are checking
actually that the SDI, that is the socket
descriptor of the client. Suppose you get the
socket descriptor of the client to be greater than the mass per socket descriptor, then you are checking
this fund each. And actually, if it is greater than this max underscore as Stephen will be modified
with that descriptive value. So this is what you are doing. Heal. Then again, the I gets
incremented, I becomes one. Therefore, you will
check this condition if it is less than
Mexico and he is, then you will see here that
client socket subscript one. What it will return
obviously now we are considering only one
client to be connected. And therefore this client
socket subscript one will have the 0 value and also the rest of them
area elements will have the 0 value because only
one client is connected. Therefore, only the 0th element
of this array is having the saccadic descriptor of the first line and rest of the array elements
are having zeros, so this will be 0 and none
of them will be satisfied. So in this manner, this loop will go on till max
underscore outlines and this condition will
not satisfy from one to max underscore
clients on the, it will be satisfied initially
that is Isaac equal to 0, then add that case only
at court satisfied later on of the iteration
of the for loop. It will not be satisfied once this for loop iteration
has been completed. And what is bad? Simply a display message
actually repos select. Now we are calling the
select function here. Now in this select
function of I envy call, Actually we are
passing this value. This value is modified
max understood as t here. Then this lead up DSO VR, lead FDA says Having
bought now to descriptor, that is one, the server socket, descriptive lines,
hyper sockets. So there are two descriptors
in this deed of DSB want to monitor both of
them for reading purpose. And this value null, null and this last value null. That is you have to keep
on waiting till you get any descriptor
socket to be ready. So you have to wait and wait. Therefore, you are
given this null. You again control actually, depending upon the value you give here it
can be controlled. Therefore here it will be
keeping on waiting actually. So suppose there is
some activity on this client socket which
you weren't actually, at that case actually, it will select, will return actually be
that descriptor set. This example I've chosen because suppose I
write some eyes, I have some message
on the line console. That means something I'm writing on that
line socket, right? And that would, that message should be read
actually, therefore, since we are monitoring in our program for reading purpose, therefore, I'm
writing something on the client so that
we can read it.
24. Session13 Program&Execution Select MultiClientServerComm 3rdHalf: So therefore there is
something to be some data to be read on the client socket till now we have
seen that one cell. What is that one client? Is there a connection
has been accepted, actually message has been
sent from server to client. The next thing what
we will do actually, we will try to write
something on the client. Once we write something
on the client, that means some
reading activities should be done because
we are writing on the socket for the client
and some data there on that line socket which
is supposed to be read. And therefore in that case then select function will return
actually with something. Then we write something
on the client, then it will return actually. And then we have to check again the condition
actually where the row, you have to check each
of their incidence here there are two descriptors. That is one for the server,
one for the climate. Perceive some activities
done on the server site. Visit this condition is checked. For now when we write the
message on that line, there is no activity
done on the master, so therefore, this condition
will not be satisfied. Then what will happen? For-loop is outside
the tip condition. Therefore, this condition
will be checked. Bacteria, this condition I
told you this is Doumani, this is for input IO
operation on the client side. So here I is equal to 0. And again, the client
socket of 0 will be, you know, that that is
already one client connected. Therefore, this will
return a non-zero value. Therefore, again,
you are checking this 0th element
of this array will have the first descriptor of the Postal is
client actually. So since I'm writing something, suppose I'm writing some
message on the climate, see how to how I will achieve actually one side
and secure the program. You will explain, you will
understand it more better. It will tell you understood
what we are doing. We are this side, where is their client, is their servers sending
message to that line? And suppose we write the
client console is hello. So therefore, hello is VR. We are writing on
the client socket. Therefore we are suppose
there is some data on the client socket and
we're supposed to read it. And they're put in that
case. Again, we're checking. We have seen that select
function is called and see whether any
activities and yes, activities done actually,
there is some data available on the client socket which
is supposed to be read. And therefore, this
condition is Wilczek. V is equal to said, that
is the decline socket, whether it is present
in this leader VS. I told you after the
select function, it will be modified. Since we added calling the
select function that is here, we are calling the
select function. And since I wrote
something on the client, there was some dataset
which is supposed to be read on the console, and therefore this
will be modified for this leader VS will have the
socket descriptor or client actually will not have a socket descriptor of the
master because we're not doing anything on master
officer disability modified on the octet. Select returns in each allele. This is having two descriptors sets at one side,
write the message, on the one side, write the message on one side writes anything
on the client socket. This will have on the
descriptors line, not on a sidewalk. And therefore, the reason this will not be satisfied actually, that is this one in this
socket descriptor of servers. Then notice not there because we are doing the activity on the client reading activity
we have to do on the client. And that board here. Since this value is non-zero
value and yes, I'm done. I've written some message on the client socket which
is supposed to be read. And therefore the
speed of VS is having only the socket descriptor
of this client actually, and therefore this MV
is equal to set, yes. And now what we're
supposed to do, I'm simply printing
a message which will be displayed on
the console and I'm supposed to read it in the socket descriptor
of the client actually, and I will read it
and it will be, I will be collecting
whatever I read from this socket descriptor of the client I'm collecting
on this buffer. This is the use of the buffer. I told you, I have
declared this buffer to be an EDI actually
off characters. You can see here. This is buffered, this message, whatever I'm writing
on the client socket that I wanted to
read actually so that I will collect
in the buffer. Actually the error checking. This is what error checking. If some edit occurs
while reading this condition
will be satisfied. This block will be executed. But if the reading
is successful, this eds will be
executed and leaving. And this is since
what I told that whatever I'm writing
on the client socket, we will see how I
am at stealing it. After completing explaining
these instructions, we'll run the program, you will understand what we're doing. So suppose I'm type any
message on the client socket, we are supposed to read it. So therefore this read is done. Again, I pulled since we will do occur the same
message on the plane. So if I missed hello
is on decline. Socket. Then the next thing
on the next line, I will get hello only because I'm acquitting the same thing. So how I will get the hello on the next line by this thing. As condition I have again
send the same message, the message which are images
collected in the buffer. Actually, you can see I'm again calling
the second function. I'm calling the
same function and passing the line socket
descriptor itself. And I'm passing this buffer, which I've read actually
from the client socket. That only the same thing I'm passing against all
the client socket, you will see the same
thing printed actually. This is how the flow goes. So I will absorb you understood
this point actually. So let's execute the program and then you will
understand it more clearly. So this is how we are
done with the coding. This socket actually and
weak in this manner, we can launch into odd number of lines still
we cannot exceed only portable and clients can
be connected since we are writing here
as client socket, maximum client should be ten depending upon
your requirement. If you want to
anticlines sockets, then you can give this value as trendy or you can hedge,
define that value. Now let's run the program and see how it will be executed. So this is my domino actually. Just a second. Yes. You can see here I'm having this program which
I have showed you. Now, I will compile, since we have to compile a
C program in on the Lena's, we are having the
feasibility to execute the command in this
command prompt actually. So if it is a C language, therefore I'm using
a GCC compiler, which is already, which was
already installed in system. I don't need to
explicitly install it. Then I will mention which file to compile
GCC compiler tool, cross-compiler
tool which is used to program the C language frame. So therefore, you can see here, you can see here no
error message has come. Let me do ls to initially we
heard on this one C file. Now after compiling, I
go on this a dot out. This is my side was i
now let me launch or execute my sidebar by
simply running this. Now, you know, when I
tried to run the server, let's see what will happen. You can see here what I'm getting myself while I'm
getting this message which I have given on the Salvo's side
listener on port 888, waiting for the connection. Whatever message I have
given on the server side, I've got all of the things. Value of the master
socket to be three. So this is just, they just
know what is the socket descriptor of master
socket at a server socket. So I've just printed this value
and it is three actually. And now this, all these lines that is in four
loop to add child socket. So you can see here, since there are no clients, socket which is added
actually because there is no client which we have
launched that but none of them. We will be area, area of the client
socket will all, it will have all 0
socket descriptors because none of them, we have not launched any, any of the client socket. And this is before cell select. You can see here before the select actually that
means this display we have. Print it now. You can see how control
is waiting here. That is, our control is stuck
and the select function. Why they started at
the select function, because we are mentioning
the timeout to null. We know when we
give the timeout to be knowledge will be
waiting for them. Some activity to occur
actually incense to be honest, at this point we
are simply adding the master socket in odd
row, read empty set. Therefore, it will monitor whether some activity
will go on that, on, on that side, what socket there'll be, don't
get a solvent. What activity can
be happening on the server socket if we are
trying to launch deadline. I'm connected to the same
port number on the socket. Then only there will
be some activity. Then it will, then we
will get the message after select printed actually then this select will not read. That is the reason I am
displaying this message. So as i, so that you can
get what I'm doing exactly. So let me show you. At this point we are having only survive launch
nullclines launched. You can see here on this client socket
descriptors that are ten clients sockets which we are taking and
all the scripts, those, but all those
ten lines sockets initially 0 because none of
them as we are launched, we are not launching
any on them. And this socket is
for the server side, the master socket, which are, which I'm simply printing here. Actually. I heard actually. And
then you can see here. You can see here we're getting all these messages
listening on the port, on the server side, waiting for connection on
the server side. Then this while loop is loop
through this infinite loop. And it depends when
you are returning, if you are exiting
from your client, then this will return actually. So these things, we are giving this starting you
and you can see here. Md 0, all these things. So what is happening? Now? What message I'm getting
here, if you can see here, I'm getting this message in for-loop to weld joint socket. This is what actually
here you can see I'm printing the value
of the master socket. Here. You can see here I'm printing the value of the
master Socrates. The next all these lines which is printed ten
times is this one. This I'm printing. So initially
no clients are there. Therefore, this condition
will not be satisfied. And therefore, since
this will be satisfied only event that is
a client connection and this value will
be greater than 0. But since now an organized
like client is connecting, we're not launched
any client and therefore this will not
satisfy it actually. And therefore we are
getting ten times this sprint it actually
now and we're getting, this moment we are getting
before select actually. You can see the select
function is called. But we are not
getting this message. Why we're not getting
this message because it is waiting for infinite time. Actually it will wait and
you try to launch deadline. Client will be connecting to
the same port number time. Actually it will keep
on waiting and you will not get This message printed. So depending upon how you
use it, if you're given, you're simply
thirty-seconds, then it will see whether the air till that time you have
launched any client, if you have not knowledge
and the timeout has expired, party seconds or over, then it will simply
return actually, from that point,
actually it will not read and you will get
this message printed. But since I'm mentioning this last argument
is null actually, therefore it is waiting
and waiting till it gets a client connection. Therefore, you can see
the reason why I've displayed this message to
just make you explain. Now let's come on this dominant. Now let's launch the
client actually, this is, I don't, I'm not supposed to write our
client program I insulin. In order to connect
to the server. You know how to connect. I will open a new
terminal actually, and then that terminal I will tell you that actually
do the port number. So in this side, what is listening
to the port number? 88884 times eight.
And therefore I will, on the next dominant, simply Telnet on the
same port number. That means the
client is connecting to the sidelight actually. Then let's see, once the client rights to connect to the
server, what will happen. So you can see here we
get this display message. So let me open one more. Dominant. This is different
or militancy to dominance. Dominance is possible
sign and one dominant, I will try to connect
to the server. So that will be that line. So therefore you can see here, and what I will do, I will mention that local host. Here. I will give you the poll number. Suppose I give you this manner. Telnet is to connect to
the local host actually, since we are doing
this communication on those same system itself, and therefore we are
not using towards laptops and we're connecting using on the same host machine. And therefore I've given
the loop and goes diabetes will be the same
about n client is having the same IP address and we're listening on this
four times eight actually. And therefore rho,
this port number that I'm giving this
sport node itself. Once I tried to connect
actually from the client side, what I've got on
the line console, trying one to 7 dot, one connected to
low local service, connected to the local host that is connected to the server. Because my silver is
on the local host. And this acknowledgement message which is sent from server. So this rule had send this
message side-by-side has sent. Let's see what is going
on onto the server side. You can see here. Now this till this
point actually I had a control actually got, and then often I try to
connect from the client side. I'm getting all these messages printed on the
side of our sites. So now what happens
since we are trying to launch the client and it is trying to
connect to the server. Therefore, this, this. So since there is some activity on the mass per
socket that board, the select function has returned the descript proper modal mass per socket for reading purpose. And therefore there's
a new connection we got with what message is this? You can see here. We got this message after
select actually, and this condition is satisfied. That is, this condition is
satisfied because this is set, this server socket is sad because a client is
trying to connect. So therefore we
will exhibit and we got the socket descriptor
of the client. And then we are simply printing this message on the silver side, it is new connection, a new connection online sockets. So we are printing this
message and we are sending this message
actually onto that line. This messages, which one? This message for this is this
message which I told you. Acknowledgments. And from those,
you can see here, we are sending this message
here from the server site. Then we're printing this message on the soil on the server side. So just coming back to the console actually you
can see here therefore, this message, this
is just print f, which I have given on the server site
acknowledgement message. And then this is the message
which this already sending. Actually when we call
the same function from the server program, then this message will be
sent on to the clients. So on the client side, you can see the
messages it received. You can see how the side, whereas communicating
with that line, how the message we got from data on the client server has said, now, the second thing
we will see, now, we have simply put the descriptor of the server
socket onto the database. And let's do activity
on the client socket. Actually, let's write
some message and let's see actually
now how it will add the socket descriptor of the client onto
the read of ideas and how we will monitor it
actually for reading purpose. What we will do,
whatever message we give here onto client side, I said I want, I will be
printing on the client itself. So suppose I am giving here, so nanny, this message, once I enter, actually, this message will be sent
onto the client side. Actually, therefore, some
data is available on the client socket which
is supposed to be read. Suppose I press Enter, you can see I got tsunami, a code on the same client site. So this is what I
wanted to explain you, that I'm writing some message
on the client socket. One side, I write the message as solely on the client socket. What will happen? Let's come here. At this point. You can see here, once
the control goes here, actually, again, the control comes here
since initially this, this condition will not be
satisfied because we are not adding the client
socket to read FDA's. But we got actually this value, but actually there is
clients are 0 will be having socket descriptor
before his client for it will be
non-zero value for this condition will be
satisfied and we are adding this line socket actually descriptor
in this read IVS. And therefore, we can now
monitor actually because we are also adding that line socket in that reader via
socket descriptor. Once this select
function will be waiting actually read FDA's will be
having two socket descriptor, one socket descriptor for this one socket
descriptor product line. Now since we, once we write
the message actually on the client side actually be
typed and the message on the client as knowledge in
that is what will happen. Something is dead on
the client socket. We have written some weird, I think something on
the client socket actually that is as deco, we are supposed to read it. There was some activities net on the line, utility purpose, and therefore, this select
function will return actually. Therefore, this condition,
once it will be checked, that is every set, this socket descriptor will
be not bred in this video ds, as I told you after the
select function it's called, then in that case
it will return with only those descriptors which are already ready for reading purpose now must be are not doing anything
on the server socket. We are writing on the client
socket and some data is that on the client socket which
is supposed to be red. And I put this condition
will not be satisfied. Yes. Then what will happen? Then this for-loop is dead outside this
condition and therefore, we are again checking this for loop will iterate actually, it'll that much amount of time. Therefore, this client
socket from zeros, so we know that only
one client is there, and therefore this will
be non-zero value. And therefore we are
checking FD is set whether you're checking
whether some activity, whether this client
socket descriptor is president read a VS. Yes, it is dead at this woman because you
are, you are right. You have written something on that line socket which
is supposed to be red. Therefore, this video
has been returned. Actually, it is n. This value is modified with the
socket descriptor or applying, that means this. So blind soccer descriptors present in this in VS actually, because this will be
modified after calling the select function with those descriptors which are
ready for reading purpose. Since now activity is done
on the applying level only debt client
is active bacteria and this will be true. And in that case you will get clients of quality
rating is said this message you will be getting on what site and what you
are doing actually here. You had reading that message, you are calling
the read function. Whatever message you got. So I have written solely
as on the client socket. So that message will be I'm
collecting onto the buffer. Actually that will end
afforded that message. And since mandating
be successful. If else condition will be satisfied and that only
message I'm trying to send. So you can see I'm calling the same function and this is the socket
descriptor for that line. I'm sending the same message actually on to this
client socket. I'm sending this tsunami on. Since this message which I'm reading from
dark line socket is I'm collecting in the
buffer and I'm parsing the same message by
calling the same function. That is the reason I'm echoing. So therefore, I'm going to
call the same function. That means I'm sending the
same message onto the client and I get this second
message to be printed here. I hope you understood
the whole logic. Actually using the
select function, how you can have a control, how much time it needs to be. If you want to wait
only for ten seconds, thirty-seconds, you can
simply change this value. This is just to explain you how you can have the feasibility
for changing the time, how you can control actually
the amount of time. The select. Again, wait, Actually, if
you want party seconds, you can wait for that time also. Though, goal programming
all about. So I will. So you got eaten every thing. Let's switch on to yes. We are done with the whole
writing the program and execute English for achieving though multi-cloud
cellular communication. Also one more thing of friends. Let me also show you launch, launch another terminal
actually just a second. Yes. This was only one client or suppose I'm trying to connect. I'm opening the third terminal. And again, the same thing. This is also this is also, yes, This is I'm trying to
launch a second client. This was what poets clients. So you can see three terminals
or terminal port server, one communal purpose client, and second one
domino is possible. Second pulmonale is
formed before his client and for the second plane. So suppose I'm
doing this source. Again, it will try to send, again this client
send a request, connection request
to the server, so sideway will accept
it actually N will send an acknowledgment message
to the second client. Actually, you can
see acknowledgement sent from the server. And suppose I messages, hello, messages, hello, goodnight message will be again a code actually
on to the client. We're typing them, I say, hello. You can see how many people's
minds I have known TO. Now coming. Now, we are done with
the whole writing the program and executing
using the select. In order to achieve multiline
server communication, you can see how the
select this feasible. Now, in the next session, we will be seeing these things actually what all things
we will be covering. Just a second. Yes, we will be covering what
is the non-blocking socket. So first of all, as I told you, we should not go for the approach of creating
a thread for each plane, which Rights Clinic,
we have seen her decide one pages in
the previous session. So instead of that, we can
use the select function. I have also written
the program that is also another way in
order to achieve them, I decline satellite
communication and that is why you are making the
socket is non-blocking, locking that we will be
seeing in the next session. Also, you'll be
seeing the difference between the two approaches. That is, in order to achieve multi client-server
communication approach, like using the select function. We have already seen
how to achieve what are the advantages and
also the difference between the non-blocking socket so that we will see
you on the octet covering what is non-blocking
socket in the next session, then we'll see the difference
when to use the Select, when to use non-blocking. So all these things will
be covering which one to use when either select
on one dropping socket, all these things will
be covering and how to make the socket is non-blocking
that I will explain you. Another session I will dedicate for writing the program and executing it using
non-blocking sockets. So since till that time we will be aware of how to make a
socket is non-blocking. We will also write a program and executed in Linux
using C language. Making the socket
is non-blocking. So all the things we'll be
covering in the next session. Please be ready for
the next session. Thank you for now.
Thanks. Are not friends.
25. SocketSession14 Makingsocket as NonBlockingSocket MultiClientServerCommunication: Hello friends. Today we will see how to make the socket as
non-blocking in order to achieve multicolored Server and Linux operating system
using C language. Prior to this session, we have seen different approach in order to achieve them and the client server communication. And that was by using the
select function and we have seen by it is used as well as
the details about it also, we have written the program and executed the nurse
operating system. Now let's see the
different approach to make the socket is non-blocking in order to achieve the multi-class
server communication. So let us see the
topics that we'll be covering in this
complete session today. We will be seeing what is
the non-blocking socket. Then the difference between the two approaches in order to achieve anticlines
server communication. That is difference between Select function and then
non-blocking sockets. So since we have seen how
to use select function and the program as well
as execution of it. Now here in this session, we will be seeing
non-blocking socket. So once this non-blocking
socket topic is covered and we
will cover this, the difference between basilic function and
non-blocking socket. Then the next thing we will
be covering which one to use. Let us read. Then. We have to use select function. All we have to use the
non-blocking socket and men weekend. And even on them. Then
we will be seeing how to make the socket
is non-blocking. We'll see the example. These are the topics
which we will be covering and release such and to
let us do one by one. The very first that is
the non-blocking sockets. So what does this
non-blocking socket making the socket
as non blocking? We'll check if the
event has occurred. And if yes, then it will process at a time
itself an else, it will return immediately
without completing, and hence the cells and the purpose of
non-blocking socket. By this definition,
it means that it will be checking you out and picking the socket
is non-blocking. And suppose we are
calling the function, then in that case it will
lead function will be called irrespective whether
data is present or not. It will return immediately. So infant data is president
well and would it will read it and it will return
after reading the data. But the data is not present on socket which you have made
it as a non-blocking. It will not wait for the data. It will simply return
a bedtime itself, so it will return immediately. So you can understand
whenever we make the socket as non-blocking, we're not supposed to. We are simply supposed
to act immediately. So it will return
immediately that this is about the making the
socket as Non-blocking. So we'll see what we can achieve by making the socket
is non-blocking. Then the example
actually the same, an example which I
have given you now, that is if you make the socket is non-blocking and
if you call the V, and if this data on the
socket, then it will read it. But if not an integer returns
successfully embed is data. That is no data,
then it will return immediately without
waiting for data to come. So this only M explained now, I hope you understood now, what is the purpose of making
the socket is non blocking. What things can be achieved? Then? It will also it returns, and that is the error
since it is no data on the socket and you are calling the function, there is no data. So as a behavior is that it
is not supposed to read, so dipole it will
return immediately. Therefore, you can
understand it has, since there is no data could not perform reading actually, without meeting it
return immediately and it will return the error. That is E would block as audit can return
later as the same. That is, again, what
does this arrow means? It means the read call would have blogged, but
it is scripted, was placed in the
non-blocking mode and saw you I support to call
the read of the sometimes. So. I hope you understood
this meaning of this error. It means that eating
function mature call could have been the docking
call actually is. But you, you, since you
are making the descriptor is non-blocking mode
actually before it returned this aaron by
the saying it could be a blocking call because you can understand
there is no data, and therefore, if there is no data it was supposed to read. But since you are making
the socket is non-blocking. It is saying that you had made still this socket
is non-blocking. Therefore, it didn't wait a bit for it, it returned immediately. So that means you are supposed to call the read function after some time so that when you call after some
time, it can happen. That and bedtime
present on the socket. So this is how we achieved the things
actually in case of, in case making the
socket is non-blocking. So you can understand
the behavior. This is how it performs the functionality when you make the socket is non-blocking. So I hope you understood
what is the purpose of making the socket is non-blocking
and how it will behave. In case of the select function. What was the case
select function ME was supposed to avoid sending all the descriptors
which we wanted to monitor, and B was giving the timeout that deadline
till what time it should be. If some of the
sockets are active, Ready, ready for reading, already, ready for writing. And in that case, it
would return number of, return those sockets and you will perform the
operation immediately. Within that timeframe of Socrates would not
become active, then it would not return
any of the sockets and operation would have
performed in case of the select function. So it is like, depending
upon the timeout, you can control the
select function. What amount do you have
to bleed actually, and whatever it will
be the result if it is if there is data or
if there is no data, but it will expire. After that. I mount actually. But in this case you
can see it will return immediately if you made this
socket is non-blocking. And if there is no data, then it will return
with this edit. And again, you can call the
reading function and you can simply check if defense
present and if yes, it redid it and return. If not, it will still
return immediately again, you simply call it
intervals of time. You can call the same
reading function. This is how this behaves when you make the
socket is non-blocking. I hope so. You understood
the difference. Let's see. Now, the example which
I've explained you make calling the
reading function if you make the socket
is non-blocking mode. Now, in case of the Unix, actually if it is a Unix
or Linux operating system, then the error that can
come actually when there is no data on the socket
can be either block. Whereas if it is a bad as it is, if it is a window
operating system and Beanstalk you are using. In that case, the error
if there is no gate on the socket will
be of this type, that is W SAE woodblock. So this is just a difference
between the arrows in case of Berliners as well as the
Windows operating system. So now you must check the error code that is
error number in the unix. And if it is Windows, then you should see by WAC, get lost error function. You can just getting on with other tasks and thumb back
later to read the socket. But if it's any
other socket area, then you have to handle it. So it's the same, but in case if you meet the socket
is non-blocking. So if there is no
data present on the socket and still the
read function is called. In that case, it will not return immediately and
it will throw the error. So by better, you will
get to know that you are supposed to call the
read function again. In the meantime, you can
carry with other tasks. So in this manner it will not make your
program as blocking. You can Eddie with
some other ask, your program will
not be staggered. And you can also end if
it is any other error. If it is not this edit
actually which is specifying that if
it is other error, then you have to handle it. Or each sockets in case of venue meet the socket
is non-blocking. This is all about
the non-blocking. Now let's see the other topic in this session
that is difference between the select function and making this socket
is non-blocking. These differences
we will be seeing. Then you may prefer
uproot of calling the select function
in order to achieve declines server communication.
Then what happens? First of all, the things
that it will require. Learning some new
concepts actually, as well as writing 20
to 25 lines of code. So we have seen when
we use select function in the program itself in
the previous session, we can have seen that we require to learn some new concepts like empty set actually and
modal macros are used, what all functions are used and what we are supposed to do. And there are lines, this default lines of code
we have to write when we use select function
that is mandatory. In case when you make both, socket is non-blocking
when you don't use select and you make this
socket is non-blocking. And in that approach,
what is that? First of all, it involves less sporting event we make
the socket is non-blocking. It will involve a lead
scoring adult show you in the program in the next session also
will see a simple example. Do three lines of code how
to achieve non-blocking. But you will write
a program properly program and we will execute
it in the next section, we will see involves less code. And you have to just modify your testing and
for the errors by adding the test for a
woodblock and E again, so what you are supposed to do. Here, when you make the
socket is non-blocking. First of all, it will involve
the less code and you have to just add the test. Actually, there is an error. It would block and
EOG and then you have to add some code for that. Actually, that is you can
call the same function again, there are other arrows, then you have to handle it. This is actually regard with respect to the
lines of the code. There are more lines of
code and select function, but less lines of code
in non-blocking sockets. If you mean the socket
is non-blocking, Then the next difference is that when you use
the select function, we have to write 20
to 25 lines of code. Okay? Then we can use, we can again reuse them minimum, minimum changes in
order to manage them multiple sockets that I'm
going to keep the socrates, then you require to add very small changes in order to manage the
multiple sockets. So since you already
have written 2225 lines of code for the select function can reuse
the same lines of code. Since you have to handle
multiple sockets, actually you only minimum
changes is required. This is only the thing that only you have to
write these lines of code and the changes
whenever you modify, this will not be on overhead. It will be only on minimum
change in the case when you use the
select function. Better in case of the
non-blocking socket, you have to customize them for handling each of the sockets for different,
different sockets. You'd have to handle
them actually, and their behavior
also can be different. It can throw different arrows
so you have to handle them. So this is thing
that you have to do in case of the
non-blocking sockets. But this is managed when you
use the select function. Once you have written
these lines of code, if you have to modify, minimum
changes will be required. Now, the other difference
actually pauses select. The code will be gathered
in one place in your code, whereas the code to support
baking the socket is non-blocking will be distributed
throughout your code. And this a complicated
maintaining the code so you can understand where this description that
what it is saying. It is saying that
whenever you are using select at one place, you can gather all
piece of code which is required for it to
use select function. But when you prefer different approach to make
the socket is non-blocking, that approach you
prefer, in that case, in whole program, your piece
of code will be distributed. And this can also complicate
maintaining the code once your raw sockets increases. Actually, in that case, it can complicate actually
maintaining the whole program. The next thing actually, which one to use when and whether to use select on whether to use non-blocking
when to use them. The ad having their
importance. Let's see. First off, we can go select
approach if you wanted to centralize the
handling on declines and test and handle
them at the same time. This is the case when
you should prefer them. Whereas you can go for the non-blocking
socket approach if you want the moon distributed
beautiful approach. This is because these are
the things when you took the first select when you should report making the
socket is non-blocking. What is the necessity of the Select menu should use
the Select that we will see. And then when you should use
a non-working that we will see here in this topic. So first of all,
unnecessarily of the select. So when we write the silver, then we know that we
should be ready to react for media's events that
can happen to the server. These even scanner, good. I am sending the request
to the server can identify and disconnecting,
reading and writing. All these events happen once
the server is launched. As these calls are
blocking, reading, writing all these
calls blocking it processing explains
what any of them are. Actually two other
events will be until the processing on the
current even is completed. And so the necessity of select
occur what it is saying. It is saying suppose since
we launched this service will be no net can be different events
occurring actually, suppose some reading
is happening. In that case, the server is busy processing the reading
and there's no date, title block, other portion of your program will be stamped. It will be not able to respond to other events
actually which are happening. So this is, this is
what happens actually. And therefore, in
that case you have to refer using the
select function. So that is the thing which
I am mentioning here, that is, this
select is required. What is this one necessity of
using the select function? This isn't necessary. We can
avoid blocking actually, you can also process
other tasks. You can use the
select function and in order to avoid
blocking your program. Then also in that in
select what we give we give the list of
docking calls to monitor. Yes. And it will
block all the time. Anyone on one blocking
call becomes ready. That select will then not be blocked Once it
caused already one. So you can understand
what we are saying. You're saying that, you
know, letting select we are giving this dog dog
descriptors sockets, sockets, descriptors we are giving that is listed
on the sockets. Which we have to monitor for
reading or writing actually. Then what will happen? And you are giving
the timeout value. So demoed value we know
is used to control how much time the select
function should be. Depending upon what
value you are giving. A timeout, it will
return immediately, audit will return, it will
get four independent. I am still a new activity happens actually on the
sockets which you have given. You have a control. Actually, what you
are supposed to do. This is about the select. Then what is unnecessary on the non-blocking socket by this vendor is non-blocking
socket is required. So suppose by the select
codeine, what will happen? You will get list of the ready event that
should be processed after the select call is done. When it gets some of the file descriptors
which are ready, it will return both. I'll descriptors
which are already, in that case what will happen? It can happen by the time the
server and makes the call. Let us suppose one span of
the socket which you would you have given in
the select function is ready for reading. The select function will
return that descriptor to you. And you can simply process by simply calling the
read function, since you know that that socket ready for reading functionally, but let me say it
is present on it. That time itself situation
might have changed. That is the client
sending the data, it may disappear
before we try to read, before you are
performing the leading. Actually at that time the
situation has changed with this client sending the
data may disappeared. See, you can always
predict what can happen. Let us suppose the client is sending some data to the server. Server is trying to
read it in-between. Only. Some connection laws have disconnected and the data, therefore, new one, not actuation can occur
anytime we cannot predict. Not only in that case
what will happen. It was behaving properly. It return you descriptors which, which became active
actually wherein you have to process
editing functionality. Blessing. But at that time only some situation occurred due to decline got disconnected. And that client was sending the data on the socket which the server
was supposed to do. In that case, finally, the reading will not happen. In that case, you can prefer picking the socket
is non-blocking. So this thing we
don't know Mia and release these things we don't
know when it can happen. It is unpredictable things which upward and that end result
to unpredictable results. In that case, it
is report to use this approach to meeting
the socket is non-blocking. So because we know that then we make the socket
is non-blocking. So suppose you're calling
the read function. In that case, the read function will be called and if there
is data present on it, it will read it and it
will return successfully. But if there is no data
present on it, no problem, it will still return actually immediately
and it will give you, both are saying
that since the rich should have become the
blocking call because there is no data present on it. But still you made
the descriptor, since it's still you made
the socket is non-blocking. Now your support, It's called the read function
again after some time, you call the read
function again. If no data it will
return immediately. Again. You call the reading function. If there is data, it will read the data and
it will return. So this is how the non, This is how it behaves menu mean the socket is non-blocking. So this is all about. So this is another example. Actually, if we make the
accept call S non-blocking, so supposed to be I'm
making the socket is non-blocking
and we're calling them except function except happens first of all
on the sidewalk. And whenever there is a
connection from the line. So line sense of
connection request in case of the servers
server exhibit connection. But since you are
making the socket is non-blocking and that
is the accept call. All in that index and embedded snow and
actually not sending any connection and
still accept this call. And this accept is non-blocking because you are making your
socket is non-blocking, then what will be the behavior? It will return immediately. So you can understand actually
that except this side, there is no line sending the request to the
server still accept. That means there
is no connection there and it will
return immediately. It will not be for the
connection request. It will not block your program getting for bending connection. It will return immediately. Even if there is no connection, it will return immediately. It will not wait, but it gives you the error actually like evil
block only again saying that except could
have been the blocking because since there
is no connection, still you made the socket is non-blocking and therefore it
has to return immediately. So you are supposed to call the exit function
after some time. This is the usage actually you made this
socket is non-blocking. You have to behave
in this manner. So this is how it works. Now, we will be liberating. This thing actually
will be writing the program in item the next session and
we will be executing. It'll be seeing how
to make the socket is non-blocking and we
will see its execution. This is how actually you
may know the topic that is, how to make a socket
is non-blocking. So this is, this is how you achieve making your
socket is non-blocking. You have to have a softball, use the FFC and TL system call. You have to perform
this FC and TL system calls or what is this f, c and d l function. It performs the various
action on open descriptors. Descriptors is your
socket descriptors here. So it performs various
actions on the, on the open socket descriptor is the
socket descriptors micelle open it will
perform various actions, such as obtaining, changing the attributes of a file
on the socket descriptor. So what it can do, two actions it can perform
Nick appealing attributes of the socket descriptors
are changing the attributes of
socket descriptors. So far, the socket descriptors, you can understand that it
can be different at reviews. So suppose you have to make
the socket is non-blocking, so there is a quad it. You can change these attributes depending upon the
requirement actually. So you asked about simply
supposed to call them FC and deal in order to make
the socket is non-blocking. So you'll see below how
to use this FC and TL. This is how you use. First of all, you will give the first argument
as a description. It is a socket
descriptor wherein you have two upon action mode. And the second argument
you will give the command. So what Amanda,
You have to give, depending upon the requirement, what you want actually on the socket to perform that
command you will give and the lines you
can understand it can have a number
of arguments here. This is what it is
supposed to do, and this is an example
actually post-op. What we are doing if you have to make this socket
is non-blocking, calling this function
system called f, c and d l. And we are passing the first argument as
a socket descriptor. And the second is a command. So we have seen actually
skeleton let this force will be the socket descriptor
and the second will be among which you want
to perform the action. These three arguments,
it is optional for you. Here we are giving this command. We want this come on, come on to perform on
the socket descriptor. And then again, you are
calling the same function. You are passing the
socket descriptor and you are giving this, you're calling this function, you will, you are giving
this command on it. You want to set actually this thing actually on
the socket descriptor. And since these three dots, which is mentioned here,
these are options. So here in this,
you've got to make giving the flag says non-block. This is how these two lines
of code you have to write when you make the
socket is non-blocking. I have asserted in what is
the purpose of this command? Get the fill. It obtains the open flag or
adopt this script. And FCA till read, will return these results. This will obtain the source. Though, what this
visible disability do actually this
command will do, it will open the socket descriptor and it will return those X as
a result actually, so this flag will be returned. This is the purpose of this
gamma and the SEC FL come on. Amanda's us to stay status flag. What would the socket descriptor in order to make the
socket is non-blocking. You can use this flag actually that is underscored non-block. Five obsolete. You understood this particular
command that is used to obtain the open flags which are there for the socket
is flipped and repealed. Return that here in this flag and set it is used at j percent, this status Black Order script. Then you can use this
in order to make your, it is in the non-blocking mode. This is how we achieve making the socket is
non-blocking, blocking. So we will make use of
it in our next session, you'll be writing the program. Making the socket is
non-blocking in order to achieve multi client-server
communication, though this is all about making the socket
is non-blocking. So all these optics, we are, we have covered, which we have seen here. That is what is
non-blocking socket. The difference between
the select function, difference between
non-blocking socket. We have seen that how many
lines you have to code more in case when you use the select function as compared to that of the
non-blocking socket. Once we have written the code, we can reuse it and the modification is
very less if we have, if we have to manage
multiple sockets. Whereas in case of non-blocking, even if the code is list, but if there are large
number of sockets, you have to handle it, the code, then you have to
do a more task in that. We have also seen in case
of the select function, when to use the select
function when to use make the socket is non-blocking mode. And we have seen that here
for Instapoll before, it will be gathered in one place but a non-blocking socket, it will be distributed
throughout your course. It is difficult to
maintain if it dissolves. Large number, large
number of sockets. These are the differences
we have seen also, we have seen meant to make
the socket as select. We have seen what
isn't necessarily of the select function.
We have seen. We don't want the program
to stop for a long time. You can use the select function. We have a control on timeout. We have seen then
we can prepare. Making socket is
non-blocking socket instead of using
select Quantity, I've seen the situation
can occur runtime, we don't know even the
select function is returning with the socket descriptors
which are ready. But due to some other situation
like connection laws, anything can happen though. Client which was
sending data if it got, It's connected somehow, do some situation,
haphazard situation. In that case, there
won't be a guitar. The date the December, which was ready to perform
the reading operation. Since the client
got disconnected, it will not be able to read. Anything can occur at anytime. So therefore, in that case
you made the socket is non-blocking to use
when I have specified. And we have seen how to make
the socket is non-blocking. You have to give that flag. The two functions we have
seen, you have to call f, c, and d. So all
these things we are, we are bandwidth and
the next session, we will be writing
the program to meet the socket non-blocking
and we will be executing it In denotes
using the C programming. So be ready for
the next session, which will be
complete dedication to write the program
and executed. Making the socket is
not knocking in order to achieve multi
client-server communication. So I'm done for now, friends. Thanks a lot. Thank you.
26. SocketSession15 Program&Exection Makingsocket as NonBlockingSocket MultiClientServerCommunication: I look friends that
they will be writing the socket program or
making the socket as non-blocking in order to achieve multiline said Well
communication and we will be also executing it in the
Linux using the C language. So prior to this session, we have seen that
dictates how to make the socket as non-blocking. So we have seen
different approaches in order to achieve anticlines, several communication
we have seen what was the problem in creating
the thread for each client which connects to
the salvo that are various disadvantages
which we have covered in earlier session so as to avoid using that
getting a thread. But each client, we have overcome it by using
the select function. We have also seen num, importance of the
select function as well as we have
seen the details. What is the purpose of using the select function
pen to use it? And we have also
written the program and executed it in earlier session. Then we have seen the
different approach of making the socket is non-blocking instead of
using a select function. So we have seen men to use the select function when to use make this socket
is non-blocking. We have seen all of these
things in earlier session. As we know, as we are having the knowledge of how to make
the socket is non-blocking. I have explained you
prior to this session, I have explained you what
is the purpose of it? Let's write the
program as well as executed by making the
socket is non-blocking. So let me just describe you in short about the
non-blocking mode. And let's start
writing the program on the units as well as
we will be executing it. Let's start about a
non-blocking socket, as I described to you
in audio session. Making the socket
as non-blocking. This check if the
event has occurred. And if yes, then it will
process at that time itself, as it will return
immediately without waiting enhances serves the purpose
of the non-blocking sockets. So when you make, you know
that he followed whenever you create a socket blocking mode, if you want to make the
socket in non-blocking mode, we have some system call that
we will be seeing ahead. But once you make the
socket is non-blocking, then how it will behave. Let me describe that. In that case, suppose
you are making your socket is non-blocking and you're calling the
read function. You know that when the
read operation mill, it plays only event that
is a data on the socket, then only you can be that
data from the socket. So dy dt will
accompany it will be successful only whenever
there is a socket. So therefore, this
read is called. And if there is a data
present on this one socket, then it will read
the data and it will return and bedtime. But that is no data
on this organ. And you're calling
the read function. And in that case,
you know that you have made this socket
is non-blocking. Therefore, it will not
wait for the data. It will return immediately. So you can understand
irrespective if data is there or not there. It will not read because you are making a socket is non-blocking. You don't want make
your program's stuck. You don't want to make
your program hand and therefore you will return
immediately without waiting, so you won't get, this is what we achieve. Venue made the socket
is non blocking. Then what, what is the
work happens in that case, there is no data and you're
calling the function. In that case, it will return immediately and it will
give you also some errors, is that errors will
describe actually that the socket you of virtue me you were supposed to
make it as blocking. But since you have made
this socket is non-blocking when the data is not
better, don't immediately. And therefore, you're
supposed to call the read function
after some time. That is the behavior. This happens in all when you make the
socket is non-blocking. So all the details
of it I have already explained you prior
to this session. Main objective in this session
is to write the program. You will see how to achieve
how to make the socket is non-blocking and
how to execute it. The example actually, when
you negate the socket is non-blocking and when
you call Amanda Silver, cause the exit function. You know that this
exit function, first of all, it is
called on both sides. Then it is called whenever the client is sending a request, connection requests
to the server, then suburb should
suppose to accept that connection requests
from the client. In the, if you're making
your socket is non-blocking. And if you call the exit
function on the site, if there is no
client connection, if there is no client
sending a request. And since you have
made the socket is non-blocking and you're
following except function, it will not wait for. Pending clinical simply
return immediately so it will give you the
set it as I described. Do you know that it will give you this error? You would block. It means what it
means that you could have media socket as
a blocking actually, because there is no action, instead you're calling
exit function. Therefore you again calls exit function after sometimes
so therefore it will give this error indicating that
after sometime corners exit function and check whether there is any connection with it, except depending upon
the requirement, you can try definite
amount of time. So this is what
happens actually, if you make this socket
is non-blocking. So I hope so you got, now, let us see actually we have already seen in the
previous session just to shortly describe how to make the socket is non-blocking. So first of all, you have
to call this F, C and D L, which is a system called this function you
as opposed to call. And you have to pass
in this format. That is, you have to
pass the descriptive. This will be on
socket descriptor. And the second argument
will be the command. Command. Is that what you want actually to be done on
this socket descriptor, that activity you
have to mention actually as a command
in the second argument. And this three dot
indicates that you can give more options
as optional actually, if you have to use FC and teal. And also we have seen
these two lines of thing actually which
you are supposed to do and you make this
socket is non-blocking. You have to call this FC
and TL and you have to pass the socket descriptor
and the command, you want to get FL. What is this guy that fell in the next for the descriptor. And return these flexor, its role is suited to get the next actually from this
socket descriptor, from the socket
descriptor that will retrieve the flex actually, and you can collect
in this variable. And then you are calling the same system call and
the socket descriptor, but you are getting this. It is F underscore set FL. What is the purpose
of this command? It will send a status
flags for the descriptor. That in that it will send X actually in the
socket descriptor. And the third option is I, and that is optional. So since you have to make
this socket is non-blocking, you have to give this opportunity
is very much important. You have to mention
this non-block because you want to make your
socket is non-blocking. This is used actually in order to make your
socket is non-blocking. So you are giving this option as an output argument in it. So this is how you can achieve making the socket
as non blocking. Now, let's start
writing the program and executed using the C language. So I'll explain you
line-by-line instructions and then we will be executing. This session is on the
Windows operating system and the program which we will be writing on the Linux
operating system. So I have installed
here the Oracle Mm box. Actually, that will
give me the cross, I can cross compile my program on the Linux
operating system. If you don't have a Linux, you can also install
it is very much z2 install Oracle be involved, and you can simply start
writing the code there when you launch that will be involved or else if you are having units operating system, you can simply
write the program. So let's start
writing the program. That ball. Let me switch to
my Linux system. This is launched Oracle VM, and this is my operating system, Linux operating
system. So I login. Let me open the terminal first. Is my program. This let me show you the path. In my home folder. I created this void
that actually, depending upon what is the purpose of my
problem, but it's empty. It non-blocking sockets are
given that beam itself here, and that is select
socket programming using non-blocking socket. We'll open the UI phone. Yes. So here this is my
program actually. So this is my server program, or making the socket
is non-blocking. Now, let us see one by one
what we will be doing. First of all, as I've shown you this in the presentation itself, the example of the
exit function. So suppose you
make the socket as non-blocking and
it is we know that XOR function is called
on the server side. So if you are making
your eye socket is non-blocking and you're
calling the exit function, it will behave
properly embarrassed. Some client request on it. It will accept that connection. So that is okay. But
what about if there is no line connection
request onto the silver? And since you are making those network socket
to be non-blocking and your colleague,
except function. In that case, obviously, even if there is no
client requests, it will not wait for the
spending and action. It will simply
return immediately. So in that case, what
should happen actually, since you are the main
purpose of the program was that it should accept the connection the connection
request assistance that you haven't
non-standard clients, so debit, therefore, there
is no client requests. So there is no
question to accept it. So therefore, you have
returned immediately. So again, you can
call after some time, you can call except function on. And you know that it will
again check if there is any funding connection
and it is better, it will return immediately. So this is how you can carry, carry the same activity
again in an independently after some amount. We'll
do the same thing. This is the server code. I'll explain your line-by-line
the instructions. Then we will be
compiling this program. We will be executing the cerebral programs.
Since we are me. Socket is non-blocking and
we'll call the exit function. So therefore, it will simply be an OT
launching any client. So when there is still we are calling texts that
function on the solver. It will simply not wait, it will return immediately. Other and network dependent. Seen that header
we can again false exit function of the
sum among doc time. And we will see that
is ESnet if it can accept the connection
embarrassed some client connection
requests, and if not, then it will again
return immediately again through n. If we launched that client actually bedtime except function is called
and then it will accept the connection
returns successfully. This is what we will be
achieving in our program. You bought actually
what I'm trying to say, even this will be
cleared by I'll explain you line-by-line
instructions. Let's see. So suppose this is a server socket program
and we know the basics. Actually, we have
already seen how to create a socket and
the details about it, and what all functions
are required to use the service I will need
to call the main function. We need to also listen actually, we also need to
accept the connection since we will focus on
the except function. Now let us see actually this is, this is supposed to hold this setup header files which you need to declare actually. And this is your main function. This is your main function. You know that though this is main function is
an entry point to start an execution
of your program. So when the program executes, the control will come at the very first line
on the mean function, and it will be executed
line by line sequentially. So what you are doing, so first of all, what is
what we're supposed to do? Supposed to make you want actually to create a
socket on the server side. And we want to make
it as non-blocking. And we have to, whenever we are dealing with
the server socket, we have to do some goal, some functions like we have first of all by index servers
socket to port number, then we have to listen
on port number. And the third that
we have to accept an action actually
calling socket function. We know that these
three parameters, these are the three arguments
which we're passing. It says if underscore init is though address family socket, and this is a type of the
socket which we wanted to, we wanted to create
a stream socket. And this third argument is 0. This is how you create
a socket and you will be taking actually socket. When you create the socket, it will return descriptor, the socket descriptor silver, which I have named it
as a master socket, and it is of the different type. And you can see I've
declared it before using it. This is error checking. If this is all can gets failure
protect in this manner. So this is how your server
socket God created and this is the descriptor for
the server socket nameless master
underscore socket. Then now you are, you are, you're done
creating the socket. Now the next thing
is that you have to make this socket
is non-blocking. And we had seen
how many make it. We have seen enough
presentation. Let's see. Here you can see there is one medieval which is declared here. You can see we are
calling FC and TL, that is a system call. And we are doing in this manner. So this system call is
called actually I've seen till we are using this, we have to make a
socket is non-blocking. Therefore, width socket we
have to make the non-blocking. We have too many.
This server socket is non-blocking and the
whole vector will be the first argument. Then the second argument, which is that we have seen what is the purpose of
this second thing? First of all, the
secondary is a command we have seen in the
presentation and it is used to retrieve the
flex which are present. So that flag will be
retrieved and it will be collected on this in this media button which
we have declared earlier. In meningitis, one
error checking. And again, we have to follow this system called GNP
or we have seen that. And we will again pass the
first argument as a socket, which we want to make it
as a non blocking socket. That is server's
socket descriptor. Which socket which
return server socket descriptor name thus must
disclose socket that we are passing it as a first argument
in this system fought. And the second we are
passing this command that is F underscore set the thought. Processing this
flag between board, as well as we are
passing this option that is o underscored non-block. These are the flag options. So since we have to make
the socket is non-blocking, we have to give this option. This is required assist must. This is how we are making this sort of a socket whose name is mass tend to score socket
S in the non-blocking mode. So we are giving this option and this is what error checking. So you can see how these things are used actually
to make the socket is non-blocking and this
couple of lines are used actually do both
on Edit checking here. This point you
understood, I hope so. I'm creating a socket and
we are making it as an on. Now the next thing
on the server side, what we're supposed to
do is that we have to, you know, this is a structure. We are taking this as a DDR
and it is of the datatypes, struct, sock, ADD
or underscore INV, know what is the purpose
of this structure? We have to fill all the members on this media ability, DDR. You have to fill with
the port number dBSPL, the family, as well
as we have this DPLL. Since we want a
sidebar inclined to communicate on the
same operating system, same host machine, actually, the same IP address
before we will give this option IN ADD
or underscore NE. Here, you can see one by
one, this variability, the averages that we add link the details we
are giving the details, we're filling it with this
services that address family. This is an odd number to which we want the server to
buy into this port number. And this is the address details. We know. What is the purpose of this ion, indeed the ARM square an
image I have purpose in my earlier session in
the socket since we want the server and client to communicate on same
host machine, local hosts. So we are supposed to
give this and I want to explain you detail
in volume session. The training itself. Then you can see here. Then we will call
the bind function on the server socket named
as masters or can be worn to bind
this server socket, that is master socket to
this number and also that will be passed it as
a second argument is an emphasis on ADR, which we have filter
details here. Don't thought argument will
be the size on this ADR. This is the error checking. Then again, what makes we are supposed to fall?
We are done with that. Now we're supposed to listen
actually on this socket, that is server socket. And this is how much of the pending line
connection you can alone. So you can give anything
depending upon the requirement. Then again, the error
checking is done here. And then you The
main thing starts TO you saw I keep on iterating. I won't go on actually. It will be infinitely and
depending upon this thing, it will return in-between. This while loop will
go on until and unless you don't return in
these pizza code. So you have to
return in order to mount on this my loop so
you can see what I'm doing. You can see here I'm
calling the exit function. As I told you in. Since we are, we are done making the server socket as non-blocking and we're
calling exit function. It is effective, that is a
client request that are not, It will not wait. It will simply turn it on board. It will accept the connection, it will return successfully. If not, connection is not there, no plan connection is there. It will return immediately and it will give you the
error this metal. So you can see exit
function is, we're calling, we are parsing the
server socket, meaningless mass per socket. And these things. This is, this is what actually, and this gives you though. This gives you the
client descriptor, actually file descriptor. This is Dr. client
socket descriptor. You are checking actually
for this minus one. Then this will give
you S minus one. Actually. You will check
different types of error. Indicates when that is
no client connection, that is when you are not
launching the client. Obviously, if you call the
exit function and you're not. Launching that line. So obviously how it will
accept the connection, there is no client
present and it also, since we are making the
socket is non-blocking. It will not wait. It
will return immediately. So in that case, this
will be minus one. So this will be minus one when you are not locked in launching the client and still
you're calling exit function will
return immediately. So therefore, this condition
will be satisfying, that is appliance
off with minus one. And in this case you will for home different,
different checks. So you will see it edit number, which is there
actually it is off, it would block types. This error will come actually, this error means that you
were supposed to make the socket as blocking
because there is no client connection. And therefore in that case the except should have actually, but the US, since you had, you had made this
socket is non-blocking. We have you had return
immediately with no waiting for the
client request. And therefore it will
give you this error saying that disorder is present and therefore you
can simply in this case, so after some time,
it means you, after some time you can call the same function that is exit. Since at that time there
was no climb connected Newton and launch client and
therefore there was no plan. So therefore, since this is eta, you can wait for some time and again
call the exit function. So you can see this display
message will be coming. There is no pending connection and Blackboard sleep
or two seconds. So I'm making to sleep border this much amount of time
actually two seconds, then what will happen? Let me sleep is done actually. What will happen obviously, again, it will iterate, edge control will go
here actually again it will call exit function
and it again it will. If that is, if you
have till that time, if you have launched
one line actually, which is connecting
on the same number, in that case, it will accept the connection and this
wind return successfully. And you will not get this
if condition is satisfied. If you have
non-threatening line, not this socket descriptor
will not be minus one. It will be a non-zero value and therefore this
will be satisfied. And then you will be, you will be sending this
message on this client socket itself from the
server connection. And therefore, you are
writing a message from it over onto the client socket. You're sending this message, so this sand you are calling
from the server program, from the server side
onto the client socket. Therefore, you are
giving the socket descriptor of the client socket. And you're passing
this message MSG, which you are giving
is test, hey, hi. This server will send a
message to the client, which you can see appearing
it on the line console. This is how it
behaves sectioning. I will show you bought what
we are trying to do here. Clearly now let's compile
the program and execute it. So now coming back
to though, Domino, having the program,
let me just reset so that you'll understand
more clearly we are having. So let me just remove this item out and let me
run the program again. Since we have to compile this program and this program is written in the C language, and therefore I will use
the GCC compiler tool, which is used to compile the C language program in case of the Linux
operating system, and therefore I'm giving DCC. So this will be default installed in your Linux
operating system. So it's straightforward is to give this command
and you will see that it got created. Now you can simply
this a dot out. In that case, when you
execute it yourself, we'll actually end server. What does server
do since you are just launching the server and you are not then launching
the client after that. In that case, it will return actually does
calling textbook function. It will return immediately. It will sleep for two seconds. And again it will call
the exit function again, it will return immediately
to sleep or two seconds. So this will keep on happening
on DNA and again until it, unless you don't
launch your client. Once you launch a dark line, then the solver will
simply expanded exhibit the connector is successful and at least send a message
from server to client. So let's see, let's
run for as a dot out. So you can see here it is saying there is no
pending connection. It's slept for two seconds. Again. After two seconds slip, it got over again. It is calling the function. Again. There is no pending connections, so therefore it
returned immediately and sleeping Porto
seconds again, this is a continuing actually
tell you, launch your time. So let me or long-term nine, I'll open a new
terminal like this. So you can see here this
terminal is for server side. Dominant, dominant. I will be using to
launch the time. So how, since the server In communication which we are doing on the same host
machine actually. So therefore, I'm linger terminal on this
course machine and sell the new dominant
that is in this manner. And I will do, I will do to connect to the
server actually I have to, I'm doing telnet localhost
actually 0 distance this server client is on
the same local machine. I'm giving local host, that is IP address at any 0
or t because the server is binded to this port number which we have seen
in our program. So once owe, you can see here once I do ten minute
actually what happened? It centimeter, it is
connected to local host. And this message it got, hey, hi thrombus server. So let's see what
happened on the solver. Again, see inside of
months and got message. Once you launch this
client actually client send a request from you
have seen me are doing ten. Let it in that case,
what happened? Simply Bennett accepted
the connection, it was successful. And therefore it will say gotta connection and
it will report item, what message it great, We have seen how high we
are writing from the solver onto the time socket
God displayed here. Then we add, then we
have disconnected from this connection most close by the author and host
bits we have seen, which we are doing
in our program. So this is what, this happens,
not all getting again, it is waiting actually since we had put it
in the infinite loop. If we, intellectually
again, we do like this. And let me run this one. What will happen? You can see again it is, there is gotta connection. It will route them to say, Hey, Hi, So this
is what, this was. This happens actually. Making the socket
is non-blocking. You can see how it
behaves sexually. Now, coming back to yes, yes. This is how we have
achieved that. I think the program, as well as executing it making the socket
is non-blocking. Client server communication. This is how you can not
multiplet lines actually. And then the side of it, we'll simply send
a message to it and there is no client launched, it will simply return immediately and it'll
give you the message. It will sleep or
two seconds again, it will keep on
calling exit function. In that minute, a little
dune got ghetto connected. This is how it gets. This is the behavior
and we are done with this complete session. Actually, we have seen
now writing the program, you have seen what is the
purpose of non-blocking socket, and we have written the
program and executed. It. Didn't mean
I'm done for now. Thank you, friends.
Thanks a lot.
27. Socket Session16 ApplicationSocketProgramming: Hi, Welcome to this
last session of the course that this application
of socket programming. Here we will be seeing parallel. The socket programming is
used as well as we'll be seeing the real-world
applications where all the socket
programming is used. Let's see, step-by-step. So first let's quickly device about the socket which
we have seen till now. We know that socket, it is an inter-process
communication within the same or different
hooves to my chain. So the client can be present in the same host machine
which will be communicating during the
socket communication audit can be present on different,
different host machine. In the diagram, quickly
revising about it. So we have seen that there is a server and
that is a client. Will understand the
identity of the silver for the salvage should have associated IP address
and the port number, which should be having
its IP address and port number so that the client, if have to do the communication with the cell work in sync with the same IP address and the port number where
the server is running. The communication. We have seen we have seen this phenomenal and so they are communicating impairment,
mild declines. They're communicating
over the internet. Started one by one. The request will be sent
and we'll be there in the waiting queue depending
upon the program, what you have configured. If you have unfeeling, should be to decline and
action in the queue, then it will be happening. In that case, if you don't want only one line to communicate
with the server, you don't want any other kind of connection to be
in the waiting queue. So that we have seen different, different functions are therefore
sidewalk or the client, we have seen that this
is just a revision. Now, going through the areas where all the socket
programming is used. This is one by one
I have described, so it provides the ability to implement the real
time analytics. So what is this real
time analytics? You know that real-time analysis means analysis of the DNA time, but the analysis of
them will be made. For example, if you
go to different, I'd say flipkart.com,
amazing.com. You can see that if suppose
you have two parties, if a mobile phone, in that case, you can see that the in-between shopping site
will give you the display off screen guard more while covering all
because you are chopping. You're searching for
the mobile phone. So they are very much smart enough to display these things. So that denote that later
you will be purchasing the thin Garden mobilized over as you are by
chasing the mobile. This is what all about the
real-time analysis analytics also examples. If you are, suppose you are looking for some dress
in any shopping site. Visit different Instagram or Facebook you can see
you will be getting the adult age of dress itself. So that later on you can go through that
site and you can shop. So this is all about the
real-time analysis, analytics. That is, whatever you are
searching in your browser, that data is stored
and that will becoming in front of you
whenever you are on. The user will be tending to that particular thing which
is coming on or displacement. It is just an idealtype. This is what the
real-time analytics. So the socket programming is used also for instant messaging by the domino logic and
understand sending the message, instant message to the socket. Communication to our
programming is used there. Then for the binary streaming, as well as for the
document collaboration. So for all these purpose, the socket programming
is used in these areas. Then also it is used for
creating the server. Investors like web servers, mail servers, FTP servers
and other servers. So we had seen that there'll
server and client where all the socket programming
can be used for creating the server
like web servers, mail servers, FTP
servers do trans. This FTP servers required associated with the
file transport. The main you can, you can
understand what it is for the, regarding sending the
means the server for that. All the socket
programming is used. And if you talk about
the client side, then the browsers that can
be Firefox or can be grown, that is socket programming used. These are the areas where all the socket programming
or are used other areas. Most of that belief
application level protocols. You have seen File Transfer
Protocol, SMTP, POP3, big news OK, socket to establish the connection
between the client and server. And then for exchanging data, you know that FTP
is used to transfer the file from the
server to client so that all the
socket programming is used then for sending the mail, for sending different things, actually all these SMTP than
messaging on the pottery. All these things are, they will make use
of the socket. These are the applications
which will make you though socket in the communication will happen between
server and client. This is all the ideas where all the socket
programming is used, this FTP, SMTP, and hopefully
these are the protocols. Now, another thing actually
where all the socrates used, I've been to socket two, so we have seen them in
socket APIs, all these. It enables the programmer to
create advanced internet, intranet and other network capability applications
to transmit the application data
across the wire independent on the network
protocol being used, all the socket
programming is used. Then. If you talk in terms of
real-time application, these are the real-time
application where Socrates, we have seen this program on. So for that, we have done the real-time chat application between the server and client. We have seen that
TCP communication and for Windows and
for Linux itself. We have done the
program executed also how the server
box to client, client talks to server. This is the socket
programming is used, that is real-time
chat application. Then other real-time application
where socket is used. We have seen HTTP Apache server communication
with client browser. So here, this also we have been programming for
this, but didn't. We have seen that
whenever the user give any link on the client-side, browser can be Mozilla, can be grown Internet Explorer
on any other browser. Whenever the user
is giving any URL, then that browser
itself is a client. So the request will go to
the HTTP Apache server. And this client sense though, we'll do the communication with the server in terms of
sending the message, in terms of header format. We have seen this
in understanding this session because I
have covered earlier how would the client sends the
message to the sidebar in thumbs-up header format
and how the body responds by sending header
and body to the thumbs, insulin on the side or sad web incentive response to client and the page gets loaded, whatever the user has given the URL on the browser
that pays will get loaded. So we have already done
the programming for this formula, as
well as Paulina. So we have seen this
real-world application. This socket programming is
used in another application, real-time application is for taxi booking application on the socket programming is used. These are the areas where all socket programming
is used, though. I have done for this last
session of this course. Now we are done with
the complete course. Thank you. Thanks a lot.
28. SocketSession17 SourceCode: I have the source code for
all the socket programs, which I have covered
in this entire course. So you can refer it
after understanding the board that I have explained
in different sessions.