Chapter4 - AJP
Chapter4 - AJP
Networking Basics
Outcomes :-
02 IPv4 is of 32 bits (4 bytes) size and The Port number is 16 bits numbers.
for IPv6 is 128 bits (16 bytes).
03 IP address is the address of the layer- Port number is the address of the layer-
3 IP protocol 4 protocols.
06
04 IP address is provided by admin of Port number for application is provided
system or network administrator. by kernel of Operating System.
05 ipconfig command can be used to netstat command can be used to find
find IP address . Network Statistics Including Available
TCP Ports
06 192.168.0.2, 172.16.0.2 are some of 80 for HTTP, 123 for NTP, 67 and 68 for
IP address examples. DHCP traffic, 22 for SSH, 25 for SMTP
etc.
TCP & UDP Protocols
[IMP :- readUTF and writeUTF are methods used to read and write data on Input stream
and Output stream respectively.]
[ PrintStream is a class which provides methods to write data to another stream]
[ipconfig method is used to find ip address of server.]
import java.io.*;
import java.net.*;
public class MyClient
{
public static void main(String[] args)
{
try
{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e)
{
System.out.println(e);
}
}
}
import java.io.*;
import java.net.*;
public class MyServer
{
public static void main(String[] args)
{
try
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class client
{
public static void main(String args[])throws IOException
{
int number,temp;
Scanner sc= new Scanner(System.in);
Socket s=new Socket("10.2.1.45",1342);
Scanner sc1=new Scanner(s.getInputStream());
System.out.println("Enter any number");
number=sc.nextInt();
PrintStream p=new PrintStream(s.getOutputStream());
p.println(number);
temp = sc1.nextInt();
System.out.println(temp);
}
}
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class server
{
public static void main(String args[]) throws IOException
{
int number,temp;
ServerSocket s1=new ServerSocket(1342);
Socket ss=s1.accept();
Scanner sc=new Scanner(ss.getInputStream());
number=sc.nextInt();
temp=number*2;
PrintStream p=new PrintStream(ss.getOutputStream()); //The PrintStream class
provides methods to write data to another stream.
p.println(temp);
}
}
UDP Programming
DatagramPacket
DatagramSocket
InetAddress
Object
Socket
ServerSocket
URL
URLConnection
URL class