|
|
|
 |
|  |
 |
ilcizzy |
aiuto per client per favor |
14-06-2006 17:08 |
|
 |
ilcizzy |
.amico.

Registered: Nov 2003
Posts: 38 (0.00 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 0:01:07: [...]
Status: Offline
Edit | Report | IP: Logged |
aiuto per client per favor
Salve a tutti. Premetto che è solo 2 giorni che mi sbatto con sti client.
Se qlc mi aiutasse con questo client gli ne sarei grato.
Innanzi tutto il server è questo:
---------------------------------------------------------------------------
import java.net.*;
import java.io.*;
// Test d'esame: scrivere un client compatibile con questo server.
// Lanciare il server connettendosi alla macchina "hal" del Silab.
class Ser {
public static void main (String args[]) {
ServerSocket welcomeSocket = (ServerSocket)null;
Socket serviceSocket = (Socket)null;
try {
welcomeSocket = new ServerSocket(10000);
while (true) {
serviceSocket = welcomeSocket.accept();
TeacherThread serviceThread =
new TeacherThread(serviceSocket);
serviceThread.start();
}
} catch(Exception e) { e.printStackTrace(); }
}
}
class TeacherThread extends Thread {
private Socket sock;
public TeacherThread(Socket sock) {
this.sock = sock;
}
public void run() {
try{
BufferedReader read = new BufferedReader(new InputStreamReader(sock.getInputStream()));
DataOutputStream rite =new DataOutputStream(sock.getOutputStream());
rite.writeBytes("Benvenuta/o al test d'esame.\n");
System.out.println("ho ricevuto questo");
String recv = read.readLine();
System.out.println(recv);
if (recv.equals("Ci provo..."))
{
rite.writeBytes("Test riuscito: potete andare.\n");
}
else
{
rite.writeBytes("Test non riuscito: riprovare.\n");
}
sock.close();
} catch(Exception e) { e.printStackTrace(); }
}
}
--------------------------------------------------------------------------------
il client che ho scritto e che ovviamente non funge è questo:
--------------------------------------------------------------------------------
import java.io.*;
import java.net.*;
class Cli {
public static void main (String args[]) throws Exception {
String frase="Ci provo...";
//Creo una socket client con ip 'localhost' e porta '10000'
Socket client = null;
client = new Socket("localhost",10000);
try
{
BufferedReader from_server = new BufferedReader(new InputStreamReader(client.getInputStream()));
DataOutputStream client_out = new DataOutputStream(client.getOutputStream());
//ricevo il mess di benvenuto
String rcvMsg1 = from_server.readLine();
System.out.println(rcvMsg1);
//mando la frease
client_out.writeBytes(frase);
//ricevo la risp
String rcvMsg2 = from_server.readLine();
System.out.println(rcvMsg2);
//chiudo il client
client.close();
}
catch(IOException e)
{
System.out.println("Errore");
System.exit(-1);
}
}
}
---------------------------------------------------------------------------------------
Non capisco perche non vada.Grazie ciao
__________________
Un utente UNIX che fa sesso:
unzip strip touch finger mount fsck more yes umount sleep
|
14-06-2006 17:08 |
|
|
|  |
 |
Voodoo |
Ho già dato l'esame ma gli ho dato un'occhiata in ... |
14-06-2006 18:03 |
|
 |
Voodoo |
.grande:maestro.

Registered: Jan 2004
Posts: 1009 (0.13 al dì)
Location: Pisa
Corso: com. dig.
Anno: dottore :)
Time Online: 6 Days, 23:28:00: [...]
Status: Offline
Edit | Report | IP: Logged |
Ho già dato l'esame ma gli ho dato un'occhiata in volata..
code:
String frase="Ci provo...";
.....
client_out.writeBytes(frase);
Mi sembra manchi il solito carattere "\n" alla stringa sopra (oppure inserendolo dopo l'argomento "frase" passato a writeBytes). Almeno,se l'errore è che una volta ricevuto il benvenuto e ha mandato la frase si blocca tutto penso sia questo 
Altrimenti dovrei guardarci a fondo cosa che non ho tempo di fare 
Ciauz
__________________
GET DROPBOX
# il grado di lentezza è direttamente proporzionale all'intensità della memoria;il grado di velocità è direttamente proporzionale all'intensità dell'oblio (Kundera) #
BLOG: Byte Strike
ChRiS 
|
14-06-2006 18:03 |
|
|
|  |
 |
cavals |
outClient.writeBytes(frase+'\n');l ... |
16-06-2006 21:11 |
|
 |
cavals |
Trainer

Registered: Nov 2003
Posts: 49 (0.01 al dì)
Location: milano
Corso: comunicazione digitale
Anno: 2
Time Online: 1 Day, 11:16:58 [...]
Status: Offline
Edit | Report | IP: Logged |
outClient.writeBytes(frase+'\n');l
|
16-06-2006 21:11 |
|
|
|  |
 |
ilcizzy |
[QUOTE][i]Originally posted by Voodoo [/i]
... |
17-06-2006 07:43 |
|
 |
ilcizzy |
.amico.

Registered: Nov 2003
Posts: 38 (0.00 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 0:01:07: [...]
Status: Offline
Edit | Report | IP: Logged |
Originally posted by Voodoo
Mi sembra manchi il solito carattere "\n" alla stringa sopra (oppure inserendolo dopo l'argomento "frase" passato a writeBytes). Almeno,se l'errore è che una volta ricevuto il benvenuto e ha mandato la frase si blocca tutto penso sia questo 
Altrimenti dovrei guardarci a fondo cosa che non ho tempo di fare 
Ciauz
in effetti era proprio cosi.
grazie 1000
__________________
Un utente UNIX che fa sesso:
unzip strip touch finger mount fsck more yes umount sleep
|
17-06-2006 07:43 |
|
|
|  |
 |
~paolo~ |
Ciao, sinceramente non ho capito cosa si intenda p ... |
21-06-2006 10:47 |
|
 |
~paolo~ |
Il Barbie ;)

Registered: Mar 2003
Posts: 319 (0.04 al dì)
Location: Pozzuolo M. (MI)
Corso:
Anno: Dott. ComDig
Time Online: 3 Days, 22:24:10 [...]
Status: Offline
Edit | Report | IP: Logged |
Ciao, sinceramente non ho capito cosa si intenda per
// Lanciare il server connettendosi alla macchina "hal" del Silab.
è solo per dire di lanciare il server e client in locale oppure connettersi alla macchina "hal" in qualche modo e poi eseguire il server da lì?
Paolo
__________________
msn: paolo198328@hotmail.com
|
21-06-2006 10:47 |
|
|
|  |
 |
~paolo~ |
[QUOTE][i]Originally posted by ~paolo~ [/i]
... |
21-06-2006 12:21 |
|
 |
~paolo~ |
Il Barbie ;)

Registered: Mar 2003
Posts: 319 (0.04 al dì)
Location: Pozzuolo M. (MI)
Corso:
Anno: Dott. ComDig
Time Online: 3 Days, 22:24:10 [...]
Status: Offline
Edit | Report | IP: Logged |
Originally posted by ~paolo~
Ciao, sinceramente non ho capito cosa si intenda per
è solo per dire di lanciare il server e client in locale oppure connettersi alla macchina "hal" in qualche modo e poi eseguire il server da lì?
Paolo
indirizzo e porta del server "hal" venivano forniti ? in caso contrario come si potevano ricavare?
__________________
msn: paolo198328@hotmail.com
|
21-06-2006 12:21 |
|
|
|  |
 |
All times are GMT. The time now is 17:54. |
|
|
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|