10-laboratoriya ishi mavzu: Tarmoqda xavfsiz soketlarlarni yaratish Ishning maqsadi




Download 0,61 Mb.
Pdf ko'rish
bet2/3
Sana25.12.2023
Hajmi0,61 Mb.
#128309
1   2   3
Bog'liq
Secure Socket

Server dasturi kodi: 
import com.sun.net.ssl.internal.ssl.Provider;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.security.Security;
public class Server { public static void main(String args[]) {
int port = 7712;
Security.addProvider(new Provider());
System.setProperty ("javax.net.ssl.keyStore", "myKeyStore.jks");
System.setProperty ("javax.net.ssl.keyStorePassword", "your password");
//System.setProperty ("javax.net.debug","all");
try {
SSLServerSocketFactory sslServerSocketfactory = (SSLServerSocketFactory) 
SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket = (SSLServerSocket) 
sslServerSocketfactory.createServerSocket(port);
System.out.println ("Server ishga tushdi va mijoz ulanishini qabul qilishga tayyor");
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
DataInputStream inputStream = new DataInputStream(sslSocket.getInputStream());
DataOutputStream outputStream = new 
DataOutputStream(sslSocket.getOutputStream()); 
outputStream.writeUTF ("Salom mijoz, biror ma'lumot yozishingiz uchun tayyormiz!");
while (true) { String recivedMessage = inputStream.readUTF();


System.out.println ("Mijozdan kelgan ma'lumot : " + recivedMessage);
if (recivedMessage.equals("yopish")) {
outputStream.writeUTF ("Xayr, aloqa tugatildi");
outputStream.close();
inputStream.close();
sslSocket.close();
sslServerSocket.close();
break;
} else {
outputStream.writeUTF("Siz ushbu xabarni jo'natdingiz : " + recivedMessage);
}
}
} catch (Exception ex) {
System.err.println ("Xatolikni tutish : " + ex.toString());
}



Download 0,61 Mb.
1   2   3




Download 0,61 Mb.
Pdf ko'rish

Bosh sahifa
Aloqalar

    Bosh sahifa



10-laboratoriya ishi mavzu: Tarmoqda xavfsiz soketlarlarni yaratish Ishning maqsadi

Download 0,61 Mb.
Pdf ko'rish