Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [java] sockety | applet
Forum PHP.pl > Forum > Po stronie przeglądarki
uzytkowicz
skrypt się kompiluje i uruchamia i działa poprawnie w NetBeans .. ale jak odpalam go w przeglądarce to mam "Loading Java Applet Failed" sadsmiley02.gif ?


Kod
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
/**
*
* @author uzytkowicz
*/
public class NewApplet extends Applet {

    /**
     * Initialization method that will be called after the applet is loaded
     * into the browser.
     */
    public void init() {
        // TODO start asynchronous download of heavy resources
        Socket smtpSocket = null;  
        DataOutputStream os = null;
        DataInputStream is = null;
        
        String get_text;
        get_text = getParameter("text");
        
        String get_subject;
        get_subject = getParameter("subject");
        
        String get_rcpt;
        get_rcpt = getParameter("rcpt");


try {
            smtpSocket = new Socket("onet.pl", 80);
            os = new DataOutputStream(smtpSocket.getOutputStream());
            is = new DataInputStream(smtpSocket.getInputStream());
        } catch (UnknownHostException e) {
            add(new Label("Don't know about host: hostname"));
        } catch (IOException e) {
            add(new Label("Couldn't get I/O for the connection to: hostname"));
        }
            if (smtpSocket != null && os != null && is != null) {
                    try {
                String responseLine;
                
                os.writeBytes("GET / HTTP/1.1\r\n");
                os.writeBytes("Host: onet.pl\r\n");
                os.writeBytes("Connection: Close\r\n\r\n");  
                
           while ((responseLine = is.readLine()) != null) {
                add(new Label("Server: " + responseLine));
                }

                
                
                        
                        
                os.close();
                is.close();
                smtpSocket.close();  

                 }
                    catch (UnknownHostException e)
            {
                add(new Label("Trying to connect to unknown host: " + e));
            }
catch (IOException e)
            {
                add(new Label("IOException:  " + e));
            }
        }
            }
    

    }
    
    

    // TODO overwrite start(), stop() and destroy() methods



P.S uruchamiam go tym generowanym automatycznie NewApplet.html znajdującym się we folderze Nazwa_Projektu/build/*.*
dr_bonzo
Zgaduje:
aplety nie moga laczyc sie zinnymi serwerami niz z tymi z ktorych pochodza, a ty laczysz sie z onetem [dopiero jak podpiszesz apleta to jest to mozliwe]. Wiec pewnie dostajesz security exception albo cos podobnego.
uzytkowicz
jak podpisać taki applet ? winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.