HELP PLS

13 отговора 290 прегледа
#1

HELP PLS

Zdraveite, vijdam che tuk se navurtat znaesti hora i zatova iskam malko pomost. Dva dena se mucha da kompiliram edna .java v .class i ne stava i ne stava!!! Drugia problem e che triabva da napravia niakolko promeni po .java faila a ot java pochti nisto ne razbiram. Stava duma za edin socket server - CommServer. Promianata, koiato iskam e samo edna - da se prasta IP-to na clienta, kogato se connectne client, kogato se disconnectne client i kogato clienta prasta saobstenie. Prosto predi promenlivata "message" da ima edno "<IP>%20"+client.getIP()+"</IP>". Poluchava se nesto takova: client.send("<IP>%20"+client.getIP()+"</IP>"+message); Eto tova e sorsa:


import java.awt.event.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.net.*;

/**
*
* CommServer
* <BR><BR>
* Generic Flash Communication Server. All communications sent and received
* are (must be) terminated with a null character ('\0') consistent with
* the way Flash does socket communications. Any client which uses this
* protocol should also work.
* <BR><BR>
* The server accepts messages from connected clients and broadcasts (verbatim)
* those messages to all connected clients. When clients connect or disconnect
* the server also broadcasts the number of clients via a NUMCLIENTS tag.
*
* Usage: java CommServer [port]
*
* @author Derek Clayton [email protected]
* @version 1.0.1
*/

public class CommServer {
private Vector clients = new Vector(); // a list of all connected clients
ServerSocket server; // the server

/**
* Constructor for the CommServer. Begins the start server process.
* @param port Port number the server should listen to for connections.
*/
public CommServer(int port) {
startServer(port);
}

/**
* Starts the server and listens for connections.
* @param port Port number the server should listen to for connections.
*/
private void startServer(int port) {
writeActivity("Attempting to Start Server");

try {
// --- create a new server
server = new ServerSocket(port);
writeActivity("Server Started on Port: " + port);
// --- while the server is active...
while(true) {
// --- ...listen for new client connections
Socket socket = server.accept();
CSClient client = new CSClient(this, socket);
writeActivity(client.getIP() + " connected to the server.");
// --- add the new client to our client list
clients.addElement(client);
// --- start the client thread
client.start();
// --- broadcast the new number of clients
broadcastMessage("<NUMCLIENTS>" + clients.size()
+ "</NUMCLIENTS>");
}
} catch(IOException ioe) {
writeActivity("Server Error...Stopping Server");
// kill this server
killServer();
}
}

/**
* Broadcasts a message too all connected clients. Messages are terminated
* with a null character.
* @param message The message to broadcast.
*/
public synchronized void broadcastMessage(String message) {
// --- add the null character to the message
message += '\0';

// --- enumerate through the clients and send each the message
Enumeration enum = clients.elements();
while (enum.hasMoreElements()) {
CSClient client = (CSClient)enum.nextElement();
client.send(message);
}

}

/**
* Removes clients from the client list.
* @param client The CSClient to remove.
*/
public void removeClient(CSClient client) {
writeActivity(client.getIP() + " has left the server.");

// --- remove the client from the list
clients.removeElement(client);

// --- broadcast the new number of clients
broadcastMessage("<NUMCLIENTS>" + clients.size() + "</NUMCLIENTS>");
}

/**
* Writes a message to System.out.println in the format
* [mm/dd/yy hh:mm:ss] message.
* @param activity The message.
*/
public void writeActivity(String activity) {
// --- get the current date and time
Calendar cal = Calendar.getInstance();
activity = "[" + cal.get(Calendar.MONTH)
+ "/" + cal.get(Calendar.DAY_OF_MONTH)
+ "/" + cal.get(Calendar.YEAR)
+ " "
+ cal.get(Calendar.HOUR_OF_DAY)
+ ":" + cal.get(Calendar.MINUTE)
+ ":" + cal.get(Calendar.SECOND)
+ "] " + activity + "\n";

// --- display the activity
System.out.print(activity);
}

/**
* Stops the server.
*/
private void killServer() {
try {
// --- stop the server
server.close();
writeActivity("Server Stopped");
} catch (IOException ioe) {
writeActivity("Error while stopping Server");
}
}

public static void main(String args[]) {
// --- if correct number of arguments
if(args.length == 1) {
CommServer myCS = new CommServer(Integer.parseInt(args[0]));
} else {
// otherwise give correct usage
System.out.println("Usage: java CommServer [port]");
}
}
}



A tova e faila: [линк]

Ste se radvam na pomost!

Отговор
в отговор на CLASS #2

URL-a

Po-dobre izteglete CommServer ot tuk :[линк]

Blagodaria vi predvaritelno!

Отговор
в отговор на CLASS #3

Re: HELP PLS

tova ne6to be6e ot nqkakwa kniga....

eto k'vo moje da se naprawi:

waw faila CommServer.java

1.predi:
/**
* Broadcasts a message too all connected clients. Messages are terminated

dobawq6 :
public void broadcastMessage(String clientIp, String message) {
broadcastMessage("<IP>%20"+clientIP+"</IP>" + message );
}

2.sled:
client.start();
// --- broadcast the new number of clients

dobawq6:
broadcastMessage("<IP>%20"+client.getIP()+"</IP>" + "connected" );

3.sled:
clients.removeElement(client);

// --- broadcast the new number of clients

dobawq6:
broadcastMessage("<IP>%20"+client.getIP()+"</IP>" + "disconnected" );



i waw faila CSClient.java zamestwa6:

server.broadcastMessage(stringBuffer.toString());

sas:

server.broadcastMessage(getIP(), stringBuffer.toString());



tova e
Uspeh...

Отговор
в отговор на sa #4

Re: HELP PLS

10x chovek! Problem obache mi e kompilaciata. Nesto mi dava mnogo greshki. Problem li ste ti e ako go kompilirash? 10x predvaritelno!

Отговор
в отговор на CLASS #5

Re: HELP PLS

OS?
ili
kakwa operacionna sistema izpolzwa6?

Отговор
в отговор на CLASS #6

Re: HELP PLS

Izviniavai, nadiavam se da ne sum mnogo nahalen, no toku sto se setih oste nesto. Kogato clienta se disconectne servera triabva da izprasta do vsichki

1-vo IP-to
2-ro vmesto "message" da ima vtori tag primerno <status>quit</status>

Ne e zaduljitelno da e tochno tova. Prosto da ima niakakva inicializacia. Tova e s cel kogato klienta se izkluchi drugite da priemat tova i ot tam natatuk az poemam nestata.

Ako mojesh pls da go kompilirash ste e mnogo dobre. Znam che stavam malko dosaden, no ot java pochti nisto ne razbiram, a mi triabvaha dva dena za da kompiliram nesto sto gode sviastno i to pak s poveche ot 20 greshki.

Blagodaria predvaritelno!

Отговор
в отговор на sa #7

XP

Az sum na XP. No ste raboti na drug server. Ima li niakakvo znachenie, nali e class file?

Отговор
в отговор на CLASS #8

Re: HELP PLS

1.unzipwa6 wsi4ko v c:\comsrv
ot dos command prompta
2.cd c:\comsrv
3.del *.class
slagash si javata v tekushtia path (pri men e c:\j2sdk1.4.1)
4.set PATH=%PATH%;c:\j2sdk1.4.1\bin
5.set JAVA_HOME=c:\j2sdk1.4.1
6.javac *.class

Отговор
в отговор на sa #9

Re: HELP PLS

Niamam J2SDK. Rabotia s JBuilder. S nego stava li?

Отговор
в отговор на CLASS #10

Re: nqmam processor 6tot sym s MAC

path = %path%;c:\jbuilderX\jdk1.3\bin
java_home=c:\jbuilderX\jdk1.3\

Отговор
в отговор на sa #11

mi nestava

Ne stava chovek! Parvo mi pravi access dained kato napisha "del *.class"!!! Sled tva ne znam kvo narichash tekust path. Kakvo iskash da kajesh s tova? Znam che vaprosa sigurno e adski tup, no se zanimavam s JAVA ot dva dena!!!

Tva za set-a go priema no "javac" komandata ne ja razpoznava.

Mnogo 10x za pomosta! Zadaljen sum ti!

Отговор
в отговор на CLASS #12

Re: HELP PLS

1. проблема е че в тоя ZIP дето си дал линк към него всичко е с атрибути read-only, махни ги от Properties на файловете и ще можеш да ги променяш и да компилираш. Ако дава някякви други грешки пастни целия output на компилатора.
2. в момента парсването на таговете става изцяло във flash клиента. Java server-а само препраща към другите клиенти същия стринг който е получил. Ако искаш допълнителни тагове трябва да промениш и flash source-а.

Отговор
в отговор на qwerty #13

Offf

Zdr, chovek! Najasno sum kak deistva chata. Mnogo dobre znam Flash-a kakvo pravi i server-a kakvo pravi. No kogato niakoi izleze ot chat clienta ili mu prekusne vrazkata na men mi triabva tova da se razbere ot drugite uchastnici v chata. Problema e che klienta ne moje kato prekasne vrazkata da izprati saobstenie nali? :) Zatova triabva server-a da go napravi. Zabeliazah che server-a taka i taka si pishe IP-to na seki koito se connectne i diskonectne, taka che reshih da vmakna edin dopalnitelen tag sadarjast IP-to kam vsiako saobstenie prastano ot srver-a. Obrabotkata v clienta si e moia rabota. Ot Flash razbiram, ama ot Java - ne!!!

Отговор
в отговор на CLASS #14

10x hora

10x hora za pomosta! Naistina mi pomognahte. Uspiah da kompiliram CLASS file i to po-elementarno otkolkoto predpolagah!!!

sus zdrave

Отговор