DatagramPacket
packet;
private InetAddress address;
private DatagramSocket socket;
public Server() throws IOException {
System.
out
.println("Sending messages");
socket = new DatagramSocket();
transmit();
}
public void transmit() {
try {
in = new BufferedReader(new InputStreamReader(System.
in
));
while (true) {
System.
out
.println(
"Vvedite stroku dlya peredachi klientam: ");
str = in.readLine();
buffer = str.getBytes();
address = InetAddress.
getByName
("233.0.0.1");
packet = new DatagramPacket(
buffer,
buffer.length,
address,
1502);
socket.send(packet);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String arg[]) throws Exception {
new Server();
}
}
Client klass yarati
:
Package LAB8;
import java.net.*;
public class Client {
private static InetAddress
address
;
private static byte[]
buffer
;
private static DatagramPacket
packet
;
private static String
str
;
private static MulticastSocket
socket
;
public static void main(String arg[]) throws Exception {
System.
out
.println("Ojidanie soobщeniya ot servera");
try {
poluchat
socket
= new MulticastSocket(1502);
address
= InetAddress.
getByName
("233.0.0.1");
socket
.joinGroup(
address
);
while (true) {
buffer
= new byte[256];
packet
= new DatagramPacket(
buffer
,
buffer
.length);
socket
.receive(
packet
);
str
= new String(
packet
.getData());
System.
out
.println(
"Polucheno soobщenie: " +
str
.trim());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
socket
.leaveGroup(
address
);
socket
.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Natija
Nazorat savollari
1.
Protokol nima?
2.
Qanday protokol turlarini bilasiz?
3.
OSI modeli nima?
4.
UDP protokoli haqida gapiring.
5.
UDP sokketi nima?
6.
UDP sokketi asosida aloqani taminlash haqida gapirib bering
Asosiy adabiyotlar.
1.
N.X.Gulto’rayev, M.E.Bayjonova, X.Y.Davletova. Telekommunikatsiya
tarmoqlarining ishonchliligi. Aloqachi. Toshkent 2018. 248 bet. ISBN 978-
9943-5569-9-7.
2.
N.M.Jo’rayev. Telekommunikatsiya tarmoqlariga texnik xizmat ko’rsatish.
Darslik. Aloqachi. Toshkent 2020. 416 bet. ISBN 978-9943-6394-4-7.
3.
H.X.Madaminov, R.R.Ibraimov, A.P.Khatamov, A.Khotamov,
Z.T.Xakimov. GSM va mobil tarmoqlarni boshqarish. Darslik. Nihol print.
Toshkent 2021. 188 bet. ISBN 978-9943-7029-7-4.
4.
Nagesware Roo Pusuluri. Software Testing Concepts and Tools. 2013.
Himal Impessions, Delhi.
Do'stlaringiz bilan baham: |