Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766

    Come faccio una chat con un applet java?

    Ne sto usando una gratuita su un mio sito.
    Ne vorrei fare una uguale, ma senza pubblicita', e magari poi metterla in rete gratis.
    Mi dite come posso fare?
    Con quale programma si fanno le applet java?

    La chat che sto usando e' questa

    www.ischiapallavolo.com/chat.php

  2. #2

  3. #3
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    Originariamente inviato da lukeonweb
    magari imparando java?
    Si, ma io dico, delle cose gia' fatte ci sono?

  4. #4
    in java non lo so...

    ps. speriamo che ci torniamo davvero in serie a

  5. #5
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    Questo è un piccolo esempio che ho fatto......poichè non l'ho fatto per un sito ma per divertimento è un po' spoglio.....vedi se ti può essere utile; tra l'altro secondo me ci sono anche dei metodi deprecati perchè l'ho fatta col jdk1.3 provala un po' e vedi.....FORZA NAPOLI
    CLIENT:
    import java.net.*;
    import java.io.*;
    import java.awt.*;

    public class ChatClient extends Thread {
    protected ObjectInputStream iObjStrem;
    protected ObjectOutputStream oObjStream;

    protected ChatFrame frame ;
    protected Socket server ;

    public ChatClient (String title, Socket s)
    throws IOException {
    super(title) ;
    server = s ;
    frame = newFrame(title, this);
    }

    protected ChatFrame newFrame(String title, ChatClient cc) {
    return new ChatFrame(title,cc) ;
    }

    public void SendString( String s ) throws IOException {
    oObjStream.writeObject( s ) ;
    }

    public void run () {
    try {
    iObjStrem = new ObjectInputStream(server.getInputStream());
    oObjStream = new ObjectOutputStream(server.getOutputStream());
    frame.show ();

    while (true) {
    String line = (String)iObjStrem.readObject();
    frame.AddText(line);
    }
    } catch (Exception ex) {
    ex.printStackTrace ();
    } finally {
    try {
    server.close ();
    System.out.println( "Connessione col server persa." ) ;
    frame.dispose() ;
    System.exit(1);
    } catch (IOException ex) {
    ex.printStackTrace ();
    }
    }
    }

    public static void main (String args[]) throws IOException {
    if (args.length != 2)
    throw new RuntimeException ("Sintassi: ChatClient <host> <port>");

    Socket s = new Socket (args[0], Integer.parseInt (args[1]));
    (new ChatClient ("ChatClient "+args[0]+":"+args[1], s)).start();
    }
    }

    class ChatFrame extends Frame {
    ChatClient chatClient ;
    protected TextArea output = new TextArea();
    protected TextField input = new TextField();

    public ChatFrame( String title, ChatClient cc ) {
    super(title) ;
    chatClient = cc ;
    setLayout(new BorderLayout ());
    add ("Center", output);
    output.setEditable(false);
    add ("South", input);
    pack ();
    input.requestFocus();
    }

    public boolean handleEvent (Event e) {
    if ((e.target == input) && (e.id == Event.ACTION_EVENT)) {
    try {
    chatClient.SendString((String) e.arg);
    } catch (IOException ex) {
    ex.printStackTrace();
    chatClient.interrupt ();
    }
    input.setText ("");
    return true;
    } else if ((e.target == this) && (e.id == Event.WINDOW_DESTROY)) {
    chatClient.interrupt ();
    hide ();
    return true;
    }
    return super.handleEvent (e);
    }

    public void AddText( String s )
    {
    output.append( s + "\n" ) ;
    }
    }

    SERVER:
    import java.net.*;
    import java.io.*;
    import java.util.*;

    public class ChatServer extends Thread {
    protected Socket chatSocket;
    protected ObjectInputStream iObjStream;
    protected ObjectOutputStream oObjStream;

    protected static Vector ChatHandlers = new Vector ();

    public ChatServer (Socket client) throws IOException {
    super("ChatServer "+client.getInetAddress() );
    chatSocket = client;
    }

    public void run () {
    try {
    synchronized (ChatHandlers) {
    ChatHandlers.addElement (this);
    }
    oObjStream = new ObjectOutputStream (chatSocket.getOutputStream ());
    oObjStream.writeObject( "Benvenuto :-)" ) ;
    iObjStream = new ObjectInputStream (chatSocket.getInputStream ());
    while (true) {
    String msg = (String)iObjStream.readObject();
    broadcast (msg);
    }
    } catch (Exception ex) {
    ex.printStackTrace ();
    } finally {
    synchronized( ChatHandlers ) {
    ChatHandlers.removeElement (this);
    }
    try {
    System.out.println( "Chiusa la connessione con " +
    chatSocket.getInetAddress() ) ;
    chatSocket.close ();
    } catch (IOException ex) {
    ex.printStackTrace();
    }
    }
    }

    protected static void broadcast (String message) {
    Enumeration e = ChatHandlers.elements ();
    while (e.hasMoreElements ()) {
    ChatServer c = null;
    synchronized (ChatHandlers) {
    if (e.hasMoreElements ())
    c = (ChatServer) e.nextElement ();
    }
    if (c != null) {
    try {
    c.oObjStream.writeObject (message);
    } catch (IOException ex) {
    c.interrupt ();
    }
    }
    }
    }


    public static void main (String args[]) throws IOException {
    if (args.length != 1)
    throw new RuntimeException ("Syntax: ChatServer <port>");
    ServerSocket server = new ServerSocket(Integer.parseInt(args[0]));
    Socket client ;
    while (true) {
    System.out.println( "Attesa di ChatClient..." ) ;
    client = server.accept ();
    System.out.println ("Nuovo ChatClient da " + client.getInetAddress ());
    (new ChatServer(client)).start();
    }
    }
    }

  6. #6
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    Angelo1974

    Ho copiato il tuo codice, l'ho messo in un blocco note, ma poi come salvo il tutto?
    Con quale estenzione?

  7. #7
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    4
    VolanoChat (www.volano.com) // La + stabile x me
    ChatExpert (www.chatexpert.com)

  8. #8
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    Originariamente inviato da $$$
    VolanoChat (www.volano.com) // La + stabile x me
    ChatExpert (www.chatexpert.com)
    La seconda la conosco, la prima no.
    Ha qualche pubblicita'?

  9. #9
    Utente di HTML.it L'avatar di Tr|k`Tr4k
    Registrato dal
    Jul 2002
    Messaggi
    2,766
    L'ho provata... non mi piace.
    Io vorrei solo il canale della mia chat, senza andare su altri canali...

  10. #10
    Utente di HTML.it L'avatar di Angelo1974
    Registrato dal
    Feb 2003
    Messaggi
    1,107
    Salva tutti e due i file come .java, poi li compili e ricorda che al server (se non sbaglio perchè l'ho fatta abbastanza tempo fa) devi passare un indirizzo IP (per provare a casa passagli localhos (127.0.0.1? non ricordo bene ma è qualcosa di simile))....ciaooooo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.