Networking Lab CS692
Java Networking -- Socket
Server socket class: ServerSocket
wait for requests from clients.
after a request is received, a client socket is generated.
Client socket class: Socket
an endpoint for communication between two apps/applets.
obtained by
contacting a server
generated by the server socket
Communication is handled by input/output streams.
Socket provides an input and an output stream.
Installing Ubuntu
vi) Make sure you are not using a defective tester
v) Do not take too short cable wires
iv) Make sure all the 8 wires are touching the copper conductor
java EchoServer 1042
OUTPUT:-
Server socket class: ServerSocket
wait for requests from clients.
after a request is received, a client socket is generated.
Client socket class: Socket
an endpoint for communication between two apps/applets.
obtained by
contacting a server
generated by the server socket
Communication is handled by input/output streams.
Socket provides an input and an output stream.
Assignment -1
How to dual
boot windows pc with Linux
What is Dual
Booting?
Dual-booting means having two operating systems on a
computer at the same time. You can call it multi-booting if you have more than
two operating systems. For example, I've Windows 7, Kubuntu and Fedora
installed in 3 different partitions in my laptop. When you dualboot, you can
choose what operating system to choose when you start your computer.
How it works?
Dual booting requires a program called bootloader. Most
operating systems include a bootloader. Windows uses its “Windows Bootloader”
while many Linux distros use “GRUB” and “GRUB 2”. There exist many other
bootloaders such as Lilo etc. When you start your PC, bootloader is the first
program that runs. It then displays the list of operating systems installed to
choose from. Some bootloaders also have advanced features like terminal access
and recovery tools
What are the
advantages?
• Your operating system can use all your hardware unlike
virtualization, so no performance loss.
• Even if one operating system fails, you have the other
system for recovery purposes and data backup.
• You can enjoy the operating system you like without having
to completely uninstall the system you need.
Installing
Ubuntu
In the previous article, we saw how to install Windows. Now
the next step is to install a Linux distro. We'll see how to install Ubuntu.
Installing Linux Mint is basically the same.
Installing Ubuntu First, you have to download the Ubuntu ISO
image from its website. Then either burn it to a DVD or create a bootable pen
drive using Unetbootin. Then boot from the disc or pen drive. Then you'll be
given options to Try Ubuntu or Install Ubuntu. So let’s choose “Install Ubuntu”
and proceed.
If you choose to try Ubuntu, you can experience Ubuntu from
the CD even without installing. But expect loss in performance and support for
graphics drivers in the Live CD environment. When you try Ubuntu, you can
install from the Live session by clicking on the “Install Ubuntu” icon present
on the desktop. It is recommended to first try if Ubuntu works well on your hardware
before installing.
In
the previous article, we saw how to install
Windows. Now the next step is to install a Linux distro. We'll see how to
install Ubuntu. Installing Linux Mint is basically the same.
Installing Ubuntu
First,
you have to download the Ubuntu ISO image from its website.
Then either burn it to a DVD or create a bootable pen drive
using Unetbootin. Then boot from the disc or pen drive. Then you'll be given
options to Try Ubuntu or Install Ubuntu. So let’s choose “Install Ubuntu” and
proceed.
If you choose
to try Ubuntu, you can experience Ubuntu from the CD even without installing.
But expect loss in performance and support for graphics drivers in the Live CD
environment. When you try Ubuntu, you can install from the Live session by
clicking on the “Install Ubuntu” icon present on the desktop. It is recommended
to first try if Ubuntu works well on your hardware before installing.
In the next
step, you can check the boxes to automatically download and install updates and
multimedia codecs during the installation process. This would require internet
and can take longer if you have a slow connectivity. You can absolutely skip
installing and install them after Ubuntu installation is complete. But without
multimedia codecs, you won’t be able to play proprietary media files like mp3.
The next
screen will give you different partition schemes. They may vary according to
your condition. For example we had only two options. Generally, the options
are,
1.
Install Ubuntu Alongside Windows
2.
Replace Windows 7 with Ubuntu
3.
Use Entire Hard Disk
4.
Something Else
To
have more control over our partition scheme, we will choose “Something Else”.
The
next screen will list all your partitions. You can create, edit, delete and
format your partitions here. choose a partition to install Ubuntu. Ensure that
the partition has no data on it as we are going to format it.
Select your
partition and click “Change”. In the “Use as” field, choose “Ext4 journaling
file system”. Check the box “Format the partition” and choose “Mount point” as
“/”.
Linux was
made in days when RAM was expensive and was designed to be able to run in
limited RAM. So if your RAM is less, says less than 1GB, you should create a
SWAP partition in order to better utilise you Hard Disk memory in limited RAM.
You need another partition to use as SWAP partition. You normally need a SWAP
partition approximately of size twice of your physical RAM. Say 2 GB in case of
1 GB RAM. Select the partition you want to use as SWAP partition and click
“Change”. In the “Use as” field, choose “SWAP”.
Remember that you cannot store any data in the SWAP partition.
Now
click “Ok”. Then click “Install now” to begin installation.
The
next screen prompts you to choose the time zone. You can conveniently click on
the map to set your time zone.
You'll
be asked more information like keyboard layout and username, password etc.
while the installation continues in the background.
After
providing the required information, you'll be presented with a slideshow
describing some best aspects of Ubuntu.
After
the installation completes, you'll see an “Installation Complete” dialog. Click
“Restart Now” to restart your system.
Now
after restart, you'll be presented with the GRUB 2 boot menu listing all your
installed operating system. You'll find your previous Window installation at
the bottom.
Congratulations,
you have set your dual boot configuration successfully.
Experiment
-2
AIM:-Identification
of different network interface and installation of Network Interface Card.
Requirements:-
i)
RJ-45
ii)
Cable wires
iii)
Crimpler
iv)
Cutter
v)
Tester
Connection
Diagram:-
Connection Table:-
Theory:-
RJ45, RJ45s,
and 8P8C
RJ45 plugs feature eight (8) pins to which the
wire strands of a cable interface electrically. Each plug has eight
locations (positions), spaced about 1mm apart, into which individual
wires are inserted using special cable crimping tools.The industry
calls this type of connector 8P8C (Eight Position, Eight
Contact).
Ethernet cables and 8P8C connectors must be crimped
into the RJ-45 wiring pattern to function properly. Technically, 8P8C
can be used with other types of connections besides Ethernet; it is also used
with RS-232 serial
cables, for example. Because RJ45 is by far the predominant usage of 8P8C,
however, industry professionals commonly use those two terms interchangeably.
Traditional dial-up modems used a
variation of RJ45 called RJ45s which features only 2 contacts
(8P2C configuration) instead of eight. The close physical similarity of RJ45
and RJ45s made it difficult for an untrained eye to tell the two apart.
Wiring
Pinouts of RJ45 Connectors
Two standard RJ45 pinouts define
the arrangement of the individual eight wires needed when attaching connectors
to a cable - the T568A and T568B standards.
Both follow a convention of coating individual wires in one of five colors
- brown, green, orange, blue and white - with certain stripe and solid
combinations.
Procedure:-
1.Remove about 40mm of the jacket
2.Untwist the twisted paired wires
3. Arrange them in the order shown in the above table
4. Once the wires are arranged and are flat, cut them using the Crimpler so they are 13mm long.
5. Now use the crimpling tool to work. The crimp tool in the gold plated electrical contact down such that they pierce through insulations of all and make contact with the copper conductor This is called insulation displacement.
6. Now repeat the same steps to the other end of the wire to be used as the receiving signal. Except if you are using crossed connection the diagram to be followed will be different that of the straight wire connection.
7.Test the connection using a tester. If all the light are flashed and in a serial order, then the connection is perfect. Otherwise some error is reflected.
2.Untwist the twisted paired wires
3. Arrange them in the order shown in the above table
4. Once the wires are arranged and are flat, cut them using the Crimpler so they are 13mm long.
5. Now use the crimpling tool to work. The crimp tool in the gold plated electrical contact down such that they pierce through insulations of all and make contact with the copper conductor This is called insulation displacement.
6. Now repeat the same steps to the other end of the wire to be used as the receiving signal. Except if you are using crossed connection the diagram to be followed will be different that of the straight wire connection.
7.Test the connection using a tester. If all the light are flashed and in a serial order, then the connection is perfect. Otherwise some error is reflected.
Observation:-
We successfully arrange the wires
in order, insert them into the RJ45 using a crimpler and then test it using a LAN
tester
Conclusion:
We see that the LAN tester is flashing all the 8 lights and they are in serial order. Hence our connection is verified and tested
We see that the LAN tester is flashing all the 8 lights and they are in serial order. Hence our connection is verified and tested
Precaution:-
i)
Do not strip the insulation of the off the individual paired wires
ii) Be careful not to cut through my coloured
wires
iii) Check carefully before inserting the arranged wires in RJ-45
iii) Check carefully before inserting the arranged wires in RJ-45
vi) Make sure you are not using a defective tester
v) Do not take too short cable wires
iv) Make sure all the 8 wires are touching the copper conductor
Experiment:-3
Aim:- write a program in java to implement echo client
server
Algorithm:-
SERVER:
STEP 1: Start
STEP 2: Declare the variables for the socket
STEP 3: Specify the family, protocol, IP address and port number
STEP 4: Create a socket using socket() function
STEP 5: Bind the IP address and Port number
STEP 6: Listen and accept the client’s request for the connection
STEP 7: Read the client’s message
STEP 8: Display the client’s message
STEP 9: Close the socket
STEP 10: Stop
STEP 1: Start
STEP 2: Declare the variables for the socket
STEP 3: Specify the family, protocol, IP address and port number
STEP 4: Create a socket using socket() function
STEP 5: Bind the IP address and Port number
STEP 6: Listen and accept the client’s request for the connection
STEP 7: Read the client’s message
STEP 8: Display the client’s message
STEP 9: Close the socket
STEP 10: Stop
CLIENT:
STEP 1: Start
STEP 2: Declare the variables for the socket
STEP 3: Specify the family, protocol, IP address and port number
STEP 4: Create a socket using socket() function
STEP 5: Call the connect() function
STEP 6: Read the input message
STEP 7: Send the input message to the server
STEP 8: Display the server’s echo
STEP 9: Close the socket
STEP 10: Stop
STEP 1: Start
STEP 2: Declare the variables for the socket
STEP 3: Specify the family, protocol, IP address and port number
STEP 4: Create a socket using socket() function
STEP 5: Call the connect() function
STEP 6: Read the input message
STEP 7: Send the input message to the server
STEP 8: Display the server’s echo
STEP 9: Close the socket
STEP 10: Stop
Source
code:-
import java.net.*;
import java.io.*;
public class EchoServer
{
public static void main(String []
args){
if (args.length<1)
{
System.out.println("USAGE:
");
System.out.println("TCPEcho
Server portno ");
System.exit(0);
}
try{
System.out.println("Opening Serversocket
at port: "+args[0]);
ServerSocket serversocket =new
ServerSocket(Integer.parseInt(args[0]));
System.out.println("Accepting
Clients");
while(true)
{
Socket
clientsocket=serversocket.accept();
clientsocket.setReceiveBufferSize(1500);
System.out.println("client
accepted.remote address: "+clientsocket.getInetAddress());
PrintWriter out=new
PrintWriter(clientsocket.getOutputStream(),true);
BufferedReader in =new
BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
String inputline,outputline;
while((inputline=in.readLine())!=null)
{
System.out.println("got msg
from client : "+inputline);
outputline= inputline;
out.println(outputline);
out.flush();
}
System.out.println("client
dissconnected");
out.close();
clientsocket.close();
}
}
catch(Exception e)
{
System.out.println("something
went wrong");
System.out.println(e);
}
}
}
Source code for CLIENT:-
import java.net.*;
import java.io.*;
import java.util.*;
public class TcpEchoClient
{
public static void main(String []
argv)
{
if (argv.length<2)
{
System.out.println("USAGE:
");
System.out.println("TCPEcho
Client portno ");
System.exit(0);
}
try{
Socket socket=new
Socket(argv[0],Integer.parseInt(argv[1]));
BufferedReader fromServer=new
BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter toServer=new
PrintWriter(socket.getOutputStream());
BufferedReader console =new
BufferedReader(new InputStreamReader(System.in));
while(true)
{
System.out.println("Enter
something to send on server");
String tosend=console.readLine();
System.out.println("Sending
to Server.......");
toServer.println(tosend);
toServer.flush();
Thread.sleep(1);
try{
System.out.println("Reading
from server....");
String Line=fromServer.readLine();
System.out.println("respose"+Line);
}
catch(Exception e)
{
System.out.println("something
went wrong");
System.out.println(e);
}
}
}
catch(Exception e)
{
System.out.println("something
went wrong");
System.out.println(e);
}
}
}
OUTPUT:--
Opening Serversocket at port: 1042
Accepting Clients
client accepted.remote address: /10.103.90.41
got msg from client : hello
java TcpEchoClient 10.103.90.41 1042
Enter something to send on server
hello
Sending to Server.......
Reading from server....
resposehello
Enter something to send on server
Experiment :- 4
AIM:- Write a program in Java to retrieve the information about Host and Port.
Algorithm:-
Step 1: provide the full URL of the browser
step 2: use uri getHost() to get information about the host name
Step 3: use urlgetPort0 to get information about the port number
Step 4: use url get to get information about the protocol applied
Source Code:
import java.lang.* ;
step 2: use uri getHost() to get information about the host name
Step 3: use urlgetPort0 to get information about the port number
Step 4: use url get to get information about the protocol applied
Source Code:
import java.lang.* ;
import java.io.*;
import java.net.*;
class ud1
{
public static void main(String args [])
throws
MalformedURLException
{ URL url = new URL("http://www.yahoo.com");
try
{
System.out.println("host name is
" + url.getHost());
System.out.println("port no. is "
+ url.getPort());
System.out.println("protocol used is
" + url.getProtocol());
}
catch (Exception e)
{
System.out.println("error"+e);
}
}
}
OUTPUT:-
C:\Users\bumka\Downloads>javac
ud1.java
C:\Users\bumka\Downloads>java
ud1
host name is www.yahoo.com
port no. is -1
protocol used is http
C:\Users\bumka\Downloads>
Comments
Post a Comment