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




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

Client dasturi kodi 
import com.sun.net.ssl.internal.ssl.Provider;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.security.Security; 
import java.util.Scanner;
public class Client { public static void main(String args[]) {
Scanner sc = new Scanner (System.in); 
int serverPort = 7712; 
String serverName = "localhost"; 
Security.addProvider(new Provider()); 
System.setProperty ("javax.net.ssl.trustStore", "myTrustStore.jts"); 
System.setProperty ("javax.net.ssl.trustStorePassword", "your password"); 
//System.setProperty ("javax.net.debug","all"); 
try { 
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) 
SSLSocketFactory.getDefault(); 
SSLSocket sslSocket = (SSLSocket) sslsocketfactory.createSocket(serverName, 
serverPort); 
DataOutputStream outputStream = new 
DataOutputStream(sslSocket.getOutputStream()); 
DataInputStream inputStream = new DataInputStream(sslSocket.getInputStream()); 
System.err.println(inputStream.readUTF()); 
while (true) {
System.out.println ("Serverga yuboriladigan xabarni kiriting : ");
String messageToSend = sc.nextLine();
outputStream.writeUTF(messageToSend);
System.err.println(inputStream.readUTF());


if (messageToSend.equals ("yopish")) {
break;
}
}
} 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