Socket Programming
Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.
Summary
Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.
Things to Remember
The following steps occur when establishing a TCP connection between two computers using sockets:
- The server instantiates a ServerSocket object, denoting which port number communication is to occur on.
- The server invokes the accept() method of the ServerSocket class. This method waits until a client connects to the server on the given port.
- After the server is waiting, a client instantiates a Socket object, specifying the server name and port number to connect to.
- he constructor of the Socket class attempts to connect the client to the specified server and port number. If communication is established, the client now has a Socket object capable of communicating with the server.
- n the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket.
MCQs
No MCQs found.
Subjective Questions
Q1:
Write short notes on Virus.
Type: Short Difficulty: Easy
<p>A virus is a biological agent that reproduce inside the cells of living hosts. They are small microorganisms which cannot be seen by naked eyes but only seen by the microscopes. They are 10-100 times smaller than bacteria with approximate size ranges from 20-300 nanometer(nm).They need a host to grow only like animal or plants cells or another microorganism.</p>
<p><strong>Virology </strong>is the branch of medicines that deals with the study of viruses and the viral diseases caused by them. Virology focuses on the virus structure, classification, and evolution.</p>
<p> </p>
<h4>Characters of virus</h4>
<ol>
<li>Viruses contain only one type of nucleic acid i.e either DNA or RNA , but never both is contained</li>
<li>Viruses are lack of cellular organelles such as mitochondria and ribosomes</li>
<li>Viruses do not undergo in binary fission</li>
<li>Viruses are obligate intracellular parasites</li>
<li>Viruses cannot make energy or proteins independent of host cell</li>
<li>Viruses multiply inside the living cells by using host cells.</li>
</ol>
<p> </p>
<p> </p>
<h4>Morphology of virus</h4>
<p>The complete virus particles are known as virion which consists of a nucleic acid surrounded by a protective coat or protein called capsid. These are formed from the identical protein subunits called capsomers. The capsids are made from the proteins encoded by the viral genome and its shape serves as the basis for morphological distinction. Complex viruses code for proteins that assist in the construction of their proteins. The envelope is usually of host cell origin, the virus does not incorporate proteins of its own often appear as glycoprotein spike( function is attaching the virus to the host cells)</p>
<p> </p>
<p>Virion consists of 3 parts:</p>
<p><strong>1.Genetic material</strong>-Genetic material of the virus is either DNA or RNA</p>
<p><strong>2.Protein Coat-</strong>It protects the genetic material</p>
<p>3.And in some species an <strong>envelope</strong> of lipids that surround the protein coat when they are present outside the cell</p>
<p> </p>
<p><strong>Four morphology of virus is:</strong></p>
<p>1.Icosahedral(cuboidal)- polyhedral shaped appears spheres eg polio, wart virus</p>
<p>2.Helical symmetry- E.g herpes virus</p>
<p>3.Helical- Rods or filaments shaped eg tobacco mosaic virus, influenza virus</p>
<p>4.Complex or uncertain symmetry-Bacteriophages are tadpole-like(geometric head and long legs) eg pox virus are brick shaped.</p>
<p> </p>
<p> </p>
<h4>Chemical constituent of virus</h4>
<p>Virion( virus particles) may also contain a certain type of essential or accessory enzymes or other proteins and consists of a nucleic acid genome packaged into or surrounded a protein coat called capsid. Capsid together with the closed nucleic acid called nucleocapsid. Some viruses have an additional protective layer, the envelope. Virus without envelope is known as naked.</p>
<ul>
<li><strong>Nucleic acid core</strong>
<ul>
<li>Genome contains either DNA or RNA</li>
<li>The nucleic acid can exist as a single strand or double strand.</li>
<li>Genome exists as linear or circular</li>
<li>Viral nucleic acid can be infective or noninfective</li>
</ul>
</li>
<li><strong>Viral Capsid</strong>
<ul>
<li>It is arranged in symmetrically around the nucleic acid core, composed of varying in the numbers of capsomers, each of them is made up of one or more polypeptide chain called protomers.</li>
<li>It protects the nucleic acid and mediates the viral absorption to and penetration of cells through interactions with receptors on the cell membrane.</li>
<li>It is based on symmetry , viral capsids can be :</li>
</ul>
</li>
</ul>
<ol>
<li>Icosahedral ( contains icosahedral shaped nucleocapsid)</li>
<li>Helical(capsomeres are togetherly wounded to form a helical or spiral tube)</li>
<li>Complex( are complex and do not confine to icosahedrons or helical shape)</li>
</ol>
<p> </p>
<p> </p>
<ul>
<li>
<h4>Envelope</h4>
</li>
</ul>
<p>a. The Certain virus contains envelope which surrounds the nucleocapsid.Envelop is composed of a lipid bilayer derived from host cell membrane and virus –coded glycoprotein which is inserted into the bilayer and project to the outer surface of the envelope.</p>
<p>b .Viral proteins- These can be grouped as structural proteins and enzymes</p>
<p>c. Structural proteins are essential for the formation of new viral particles in which some are associated with the nucleic acid, some with capsid and envelope and they determine the antigenic properties of the virus</p>
<p>d. Some virus carries enzymes inside the virion in a small amount . These enzymes are essential for initiation of viral replication when enters in the host</p>
<p> </p>
<h4> </h4>
Videos
Virus

Socket Programming
Socket Programming
A network socket is a presented as the endpoint of an inter-process communication flow across a computer network. Today, most communication systems carried out between computers is based on the Internet Protocols. So, nowadays most network sockets that we use are Internet sockets. A socket address possess the combination between the IP address and a port number, much like one of the ends of a telephone connection has the combination between a phone number and a particular extension in a telephone system. Based on this address, the internet sockets used for communication delivers incoming data packets of information to the appropriate application process ends or the threads which help to establish the better communication between the components of the system.
Sockets provide the communication flow between two computers using TCP. And the client program attempts to connect the to the server after creating a socket on its end of the communication.
When the connection is made over the system, the server creates a socket object on its end of the communication. The client and server can now communicate by the means of socket like writing to and reading from the socket.
In JAVA language java.net.Socket provides a socket and java.net.ServerSocket provides the mechanism on how the server program listens to the clients where it establishes the best communication between them.
Steps that occurs when establishing connection using sockets between two computers:
- The server instantiates a ServerSocket object, which represents the port no denoting which specific communication to occur on.
- The server invokes the accept() method of the ServerSocket class. This method waits for a client until it connects to the server on the given port.
- After the server is waiting, a client instantiates a Socket object, specifying which server name and the port number to connect to.
- The specified server and the specific port number is used to connect the client by the constructor of the socket class. If communication is successfully established then the connected client possess the Socket object capable of communicating with the server.
- In the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket.
There are two different types of sockets:
- Stream Socket (connection-oriented): uses TCP; telnet, ssh, HTTP...
- Datagram Socket (connection-less): uses UDP; audio/video streaming
- An Internet socket is characterized by a unique combination of the following:
- Local socket address:Is resembles Local IP address and port number
- Remote socket address: Only for established TCP sockets. As discussed in the client-server section, this is necessary since a TCP server may serve several clients concurrently. The server creates one socket for each client, and these sockets share the same local socket address.
- Protocol: A transport protocol (e.g., TCP, UDP, raw IP, or others). TCP port 53 and UDP port 53 are consequently different, distinct sockets.
Fig: Process Communicating through TCP sockets
Primitive | Meaning |
SOCKET | Create a new communication end point |
BIND | Attach a local address to a socket |
LISTEN | Announce willingness to accept connections: give queue size |
ACCEPT | Block the caller until a connection attempt arrives |
CONNECT | Actively attempt to establish a connection |
SEND | Send some data over the connection |
RECEIVE | Receive some data from the connection |
CLOSE | Release the connection |
Fig: The socket primitives [Berkeley Sockets].
Example of Socket Client:- package client.server;
import java.net.*;
import java.io.*;
public class Client{
public static void main(String args[])
throws Exception{
Socket soc=new Socket("localhost",6666);
DataInputStream dataIn=new DataInputStream(soc.getInputStream());
DataOutputStream dataOut=new DataOutputStream(soc.getOutputStream());
BufferedReader buffReader=new BufferedReader(new InputStreamReader(System.in));
String str1="",str2="";
while(!str1.equals("stop")){
str1=buffReader.readLine();
dataOut.writeUTF(str1);
dataOut.flush();
str2=dataIn.readUTF();
System.out.println("Server says to the client: "+str2);
}
dataOut.close();
soc.close();
}
}
Socket Server Example:
package client.server;
import java.net.*;
import java.io.*;
public class Server{
public static void main(String args[])throws Exception{
ServerSocket serverSoc=new ServerSocket(6666);
Socket soc=serverSoc.accept();
DataInputStream dataIn=new DataInputStream(soc.getInputStream());
DataOutputStream dataOut=new DataOutputStream(soc.getOutputStream());
BufferedReader buffReader=new BufferedReader(new InputStreamReader(System.in));
String str=" ",str2=" ";
while(!str.equals("stop")){
str=dataIn.readUTF();
System.out.println("client says: "+str);
str2=buffReader.readLine();
dataOut.writeUTF(str2);
dataOut.flush();
}
dataIn.close();
soc.close();
serverSoc.close();
}
}
Stream Sockets
It is a connection Oriented Sockets used in TCP. The stream socket may serve several clients concurrently, by creating a child process for each client which helps to establish a TCP connection between the child process and the client. But those unique dedicated sockets are needed to be created for each connection when it is essential. The each socket is identified by both the local and remote IP address and port as it needs to establish the connection.

Datagram Sockets
Datagram Sockets are connectionless sockets used in UDP. Here, no child process is created for multiple clients. Single Socket serves all the clients. The socket is identified by local port no. and IP address.

Reference
- Tanenbaum, WetherRall, Andrew S. , David J. ,Computer Networks. 5th Ed. Boston: Pearson Education, Inc
- http://www.javatpoint.com/socket-programming
- http://www.tutorialspoint.com/java/java_networking.htm
- W. Stallings, “Data and Computer Communication”, Macmillan Press, 1989.
- Kurose Ross, “Computer Networking: A top-down approach”, 2nd Edition, Pearson Education
- Larry L. Peterson, Bruce S. Davie, “Computer Networks: A Systems Approach”, 3rd Edition, Morgan Kaufmann Publishers
Lesson
Application Layer
Subject
Computer Engineering
Grade
Engineering
Recent Notes
No recent notes.
Related Notes
No related notes.