0% found this document useful (0 votes)
8 views

Java (Assignment) Saksham Agrawal

The document outlines various programming concepts related to socket and URL connections in Java, including client-server communication and exception handling. It provides code examples for establishing connections, handling data streams, and using DatagramSockets for network communication. Additionally, it discusses the structure of classes and methods necessary for implementing these functionalities.

Uploaded by

Saksham Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java (Assignment) Saksham Agrawal

The document outlines various programming concepts related to socket and URL connections in Java, including client-server communication and exception handling. It provides code examples for establishing connections, handling data streams, and using DatagramSockets for network communication. Additionally, it discusses the structure of classes and methods necessary for implementing these functionalities.

Uploaded by

Saksham Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

228coN H95

Subject Date.:

Auignmunt-2
Setion-A
4

JaNa sokd
betuwn te apalicatin unning en diyunt IKE.
Tawe sorkt pognammg cam becn neton ismted a
Conneton Jea. Sokt and seA Jokot clas
and DatnganaSatket
Qmd Daa ananlacket ars Rd fau cennictin-Ju seokit
-piagomniang
2 hdhat e Port umben 2
to Auuhlch anatnet athA nituek mRe J o be

eqwuihped witn tadasdped


Auimd aunh er

name olclaues d in cennechn glentedl


and smntien les conmmnitatiÝn
Cnnectn Qriemted Seaer amd Serlien Sakeet
Cennautien -les Datagianm Soukek amd Datag1am cket
Draw t neat nd clan diagnam cent
22 BCoNU9S

Subject
Deta

CLIENT SERVER
ISscket Socketl
OPEN Listtn
Connxction
Reavest
Conrect

Clent/
Session
Taloset
Erd File

ScKET API

S.
hat te u of ohen Canneetiam mithadin URL lau 2

URL Cannectbn nltance that nilerent a


ote
Camnlcian to The emste ehiect nslamnud by The URL

Sectien-B
4. hAP t diehlay the HrTPAade ey fieldu and
Va

publc class HthlURL ConnecHon Derno


publi alatHe vaid main (Shig i ags)
URL Ur = new VRL http / www jauatpaint cam hava
tutrial
Htth VRLonnecian hic =(HHthUKLConnection) urlahen Cannetion (),
far Cinti ; ic=8, i4)
Sstmout pninttn (huc getPeaderEeldkey ) tl ="
huc disonnect O
22 BCoN95
Subject Data.

atchl Excetion e ) Sstem Oud. grintin Ces).

Output Date =Thu19 Seb 2024 21 2220


Content-Tyhe text/htm

Connectian keep-alive
Cache Control = max-age =8600
Exbires Thu9Sep 202y 22:22: 20 nmT
Location = hths: wwW javathoint Corm aya - Hutoral

2 What i Inet AddusInty AdduInts Addris c


Explainmhoduithpaamet and sutwm
Jned Addrus
IP addey t com be erther
IPVy
Methode :
y got Ey Nanme (String het): Rituwmy InitAddres object lo
Apelped hust rame
fazay o Inet Addu
0i) qctHot Name () Rtuzma HetName

founat
(V)
22 BcoN 13S

Subjoct Cate

Int Adds clas


Muthel:

faznmat
alcebback AddhuD (J: Rtunu true

Om TPVG addzies 44 txemd

Metnd

Capatible Irvá addaeis:

Addres

AP diablayig detali a am VRL ike poatocol


hatnamepat nunter fite nemename pt

public casc Shubh


pualic statc void main (string g args)

URL Vrneus URL( Ap:// wwauthoint tam


jna- tutariol ")
rlgetfrotncol() );
urkgetrost)

Sytmnut printh fieNome "


226toN113
Sbjeet Deta:

Catch (Excehtion e)f Systerm autprinth Ce)

uthut Rrotocol htth


Hast Name iwwavotoint com
Port Number '
flle Namei java - tutorial

inite a cient- senn a_plication chatti ng uing


TP |LP.

Class MuStrver
public atahc Vaid main CSthring (1 ang) throws Fxcehton
Sener Sacket ss new Server Socket 3333)
Socket s = SS -aceht (
Datn inh1dstram din nto Data EnhudSheta m(SsqetInzut Shazm))
Datn Outal Shreom dout = nauo DataluthutSteeaml Spetluthut ShreamlDl
Bulained Raadte brneus Buttred Readtr (nt ZnpuShênm Beockr
Lsyskemin));
while (Ich -eaquals (lsaj"))
Str din read TÂ (0}
Sysienm oubprintin litnt ~ay "+ Str);
str2 br.reodline ()
226coNtL9r

dùn-clase

lk Malient jaua

class Nlient

Datasnhtshmm dìn s nto Data nhtstriam sgetInhutshon

eudte UTE Cch)

S-clese
226coN 95
Subjeet Date.

2 AP to ntad th centendURL g VEL


Connocten claA
Impart laudloxX
Amhorava.net
puhlie class VRL ConnecHon Exarmhle t
public Alatic vold main CString r1ag)

URL Url =ne DR("http:/ Wwwjaatoint com An tk

URL CannecHon urlcon = yrl ohenConnecionC


Sahutsreom shom =urlcan getZnptShraml),
while (= streom read ())|=)1
Syskmaud printth CCchar)ii
Cath (Ex cehHan e)
tSysitom aud -prìath (e);

3.

Aplieatian uisng Datngram Asket and Datagram



packtt

inmport
puli class Server
public ztahe void nain ( String arysci hrouas Exception
22ßCoNI95

Subject Date:

DatagrornSocket ds == ne DatagrormSscket lsooe )) bytec)b


Ratbgtom Racket dpl,dp2)
Shrig
ss
Eutitredfeader br= new Bullered Reader (aew Snputsheam Reacder
(Syasem in) ); b= neus byte io24
do

ds-receive Cde)

Syslem oe.priatln (s)


4S-faials CMexit"))
S =brreadLine)

Dataaramfacket lh, s.lengh ()dpqcB Add cess )


dpl qed Add recc () , dpl- qeB poct()
ds. send Cdo);
IAkie ls:eq,uols ("ext")
3

liemt

imbatt laua- net.


public cass Client
pulie statit waid poain (string tiam) thraus Excehtion
Datzqra mSacket ds= NR
("pxit")) (Is-tauials while
Suslemodprintn
(S);
String
Cb neS=
)ata gt dpb=
Cdp)}dsneceive
balenyny Cb, facketpetayana nts dpl=
LinC
e ead br- S=
break
Strings
dedpj Dataqranmfacket
Defs.: Sublect
NI|95 Bco 22

You might also like