Java технологія. Основні риси та перспективи застосування, Детальна інформація

Java технологія. Основні риси та перспективи застосування
Тип документу: Реферат
Сторінок: 17
Предмет: Комп`ютерні науки
Автор:
Розмір: 19.9
Скачувань: 4069
Програма складається з 4 класів: Server, ClientConnection, Client та ServerConnection. Перші 2 класи відносяться до серверної частини, другі 2 - до клієнтської.

Клас Server:

import java.net.*;

import java.io.*;

import java.util.*;

public class Server implements Runnable {

private int port = 6564;

private Hashtable idcon = new Hashtable();

private int id = 0;

static final String CRLF = "\r\n";

synchronized void addConnection(Socket s) {

ClientConnection con = new ClientConnection(this, s, id);

id++;

}

synchronized void set(String the_id, ClientConnection con) {

idcon.remove(the_id) ;

con.setBusy(false);

Enumeration e = idcon.keys();

while (e.hasMoreElements()) {

String id = (String)e.nextElement();

ClientConnection other = (ClientConnection) idcon.get(id);

if (!other.isBusy())

con.write("add " + other + CRLF);

}

idcon.put(the_id, con);

broadcast(the_id, "add " + con);

}

synchronized void sendto(String dest, String body) {

ClientConnection con = (ClientConnection)idcon.get(dest);

if (con != null) {

The online video editor trusted by teams to make professional video in minutes