Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.net.*;
import java.io.*;
import java.util.*;
public class chatserver implements Runnable
{
public static final int PORT = 8765;
protected ServerSocket listen;
protected Vector<connection> connections;
Thread connect;
public chatserver()
{
try
{
listen = new ServerSocket(PORT);
} catch (IOException e)
{
System.err.println("Fehler beim Erzeugen der Sockets:"+e);
System.exit(1);
}
connections = new Vector<connection>();
connect = new Thread(this);
connect.start();
}
public void run()
{
try
{
while(true)
{
Socket client=listen.accept();
connection c = new connection(this, client);
connections.addElement(c);
}
} catch (IOException e)
{
System.err.println("Fehler beim Warten auf Verbindungen:"+e);
System.exit(1);
}
}
public static void main(String[] args)
{
new chatserver();
}
public void broadcast(String msg)
{
int i;
connection you;
for (i=0; i<connections.size(); i++)
{
you = connections.elementAt(i);
you.out.println(msg);
}
}
}
import java.net.*;
import java.io.*;
import java.util.*;
public class chatserver implements Runnable
{
public static final int PORT = 8765;
protected ServerSocket listen;
protected Vector<connection> connections;
Thread connect;
public chatserver()
{
try
{
listen = new ServerSocket(PORT);
} catch (IOException e)
{
System.err.println("Fehler beim Erzeugen der Sockets:"+e);
System.exit(1);
}
connections = new Vector<connection>();
connect = new Thread(this);
connect.start();
}
public void run()
{
try
{
while(true)
{
Socket client=listen.accept();
connection c = new connection(this, client);
connections.addElement(c);
}
} catch (IOException e)
{
System.err.println("Fehler beim Warten auf Verbindungen:"+e);
System.exit(1);
}
}
public static void main(String[] args)
{
new chatserver();
}
public void broadcast(String msg)
{
int i;
connection you;
for (i=0; i<connections.size(); i++)
{
you = connections.elementAt(i);
you.out.println(msg);
}
}
}
import java.net.*;
import java.io.*;
class connection extends Thread
{
protected Socket client;
protected DataInputStream in;
protected PrintStream out;
protected chatserver server;
public connection(chatserver server, Socket client)
{
this.server=server;
this.client=client;
try
{
in = new DataInputStream(client.getInputStream());
out = new PrintStream(client.getOutputStream());
} catch (IOException e)
{
try { client.close(); } catch (IOException e2) {} ;
System.err.println("Fehler beim Erzeugen der Streams: " + e);
return;
}
this.start();
}
@SuppressWarnings("deprecation")
public void run()
{
String line;
try
{
while(true)
{
line=in.readLine();
if(line!=null)
server.broadcast(line);
}
} catch (IOException e)
{
System.out.println("Fehler:" + e);
}
}
}