 |
UZI |
io devo dare l'esame domani, cmq ti posso dire per ... |
31-03-2005 12:05 |
|
 |
UZI |
free pain dispenser

Registered: Mar 2003
Posts: 2211 (0.27 al dì)
Location: monza - troppi fighetti
Corso: com. dig.
Anno: Dottor Morte
Time Online: 14 Days, 4:46:06: [...]
Status: Offline
Edit | Report | IP: Logged |
io devo dare l'esame domani, cmq ti posso dire per certo: lascia stare il multicast, non serve per fare un server multithread... sono due cose diverse.
__________________
those who test will find a bullet in they chest
put ta rest
by a brotha who was hopeless
grow up broke on tha rope of insanity
how many pistols smoking coming from a broken family
|
31-03-2005 12:05 |
|
|
|  |
 |
urcodiaz |
ok, capisco...ma se domani mi trovo un server mult ... |
31-03-2005 12:19 |
|
 |
urcodiaz |
*incredibile*
Registered: Jan 2003
Posts: 83 (0.01 al dì)
Location:
Corso: Comunicazione Digitale
Anno: 3°
Time Online: 1 Day, 1:26:51 [...]
Status: Offline
Edit | Report | IP: Logged |
ok, capisco...ma se domani mi trovo un server multithread in udp cosa faccio?
Qualcuno mi dice chiaramente se esiste o meno?
Io son sicuro che per fare server multithread si usa tcp che è più sicuro e viene meglio. Sinceramente pensavo che il server multithread in udp non esistesse proprio...Chi ha fatto gli appelli precedenti potrebbe illuminarci?
Grasias!!
__________________

|
31-03-2005 12:19 |
|
|
|  |
 |
UZI |
guarda, ti posto il codice (non completo, manca l ... |
31-03-2005 12:23 |
|
 |
UZI |
free pain dispenser

Registered: Mar 2003
Posts: 2211 (0.27 al dì)
Location: monza - troppi fighetti
Corso: com. dig.
Anno: Dottor Morte
Time Online: 14 Days, 4:46:06: [...]
Status: Offline
Edit | Report | IP: Logged |
guarda, ti posto il codice (non completo, manca l'elaborazione dei dati del pacchetto, che dipende da cosa è richiesto che faccia il server) di un server multithread udp che ho fatto ieri. questo metodo funziona da quello che ho potuto vedere, ma non mi assumo responsabilità circa la correttezza effettiva in quanto me lo sono inventato di sana pianta... auguri!
code:
import java.util.*;
import java.net.*;
import java.io.*;
class engine extends Thread {
byte incoming[];
SocketAddress sender;
public engine(byte[] b, SocketAddress s) {
incoming = b;
sender = s;
}
public void run() {
//...fˆ qualcosa coi dati in incoming
byte tbuf[] = new byte[256];
String response = //...scrive la risposta
tbuf = response.getBytes();
try{
//invia la risposta
DatagramSocket tsock = new DatagramSocket();
DatagramPacket tpack = new DatagramPacket(tbuf, tbuf.length, sender);
tsock.send(tpack);
System.out.println("pacchetto inviato");
tsock.close();
}catch(Exception e){}
}
}
public class udp_calc_multiser {
public static void main (String args[]) {
byte buf[] = new byte[256];
DatagramPacket pack = new DatagramPacket(buf, buf.length);
try{
DatagramSocket UDPsocklistener = new DatagramSocket(4444);
while(true){
UDPsocklistener.receive(pack);
new engine(pack.getData(), pack.getSocketAddress()).start();
}
}catch(Exception e){}
}
}
__________________
those who test will find a bullet in they chest
put ta rest
by a brotha who was hopeless
grow up broke on tha rope of insanity
how many pistols smoking coming from a broken family
|
31-03-2005 12:23 |
|
|
|  |
 |
francesco2 |
Grazieee UZI ... |
31-03-2005 12:30 |
|
 |
francesco2 |
.illuminato.
Registered: Jan 2004
Posts: 176 (0.02 al dì)
Location: biella
Corso: comunicazione digitale
Anno: 3
Time Online: 1 Day, 12:42:42 [...]
Status: Offline
Edit | Report | IP: Logged |
Grazieee UZI
__________________
r
|
31-03-2005 12:30 |
|
|
|  |
 |
papousek |
io lo scorso appello ho avuto UDP...e l ultimo mod ... |
31-03-2005 14:13 |
|
 |
papousek |
Prisoner

Registered: Jan 2005
Posts: 1562 (0.21 al dì)
Location: Sona
Corso: Dottore dal 2006
Anno: End
Time Online: 16 Days, 7:11:58 [...]
Status: Offline
Edit | Report | IP: Logged |
io lo scorso appello ho avuto UDP...e l ultimo modulo..quello del multithread l ho lasciato bianco..appunto perchè...come ripeto...l udp dal mio punto di vista nn è stato propriamente visto a scuola....
cmq...sperem...
__________________
Break Out
|
31-03-2005 14:13 |
|
|
|  |
 |
foxinho |
la vedo grigia domani...:(:(:( ... |
31-03-2005 14:14 |
|
 |
foxinho |
.arcimaestro.
Registered: Oct 2003
Posts: 254 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 2 Days, 14:41:59 [...]
Status: Offline
Edit | Report | IP: Logged |
la vedo grigia domani...  
|
31-03-2005 14:14 |
|
|
|  |
 |
Vale |
scusate la domanda ma le domande su C sono a rispo ... |
31-03-2005 14:24 |
|
 |
Vale |
.illuminato.
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline
Edit | Report | IP: Logged |
scusate la domanda ma le domande su C sono a risposta multipla anche quelle o sono aperte?
|
31-03-2005 14:24 |
|
|
|  |
 |
francesco2 |
[QUOTE][i]Originally posted by Vale [/i]
... |
31-03-2005 14:32 |
|
 |
francesco2 |
.illuminato.
Registered: Jan 2004
Posts: 176 (0.02 al dì)
Location: biella
Corso: comunicazione digitale
Anno: 3
Time Online: 1 Day, 12:42:42 [...]
Status: Offline
Edit | Report | IP: Logged |
Originally posted by Vale
scusate la domanda ma le domande su C sono a risposta multipla anche quelle o sono aperte?
Magari sbaglio in alcuni esercizi non bisognava inserire del codice in C? Qualcuno si ricorda?
__________________
r
|
31-03-2005 14:32 |
|
|
|  |
 |
Vale |
io per l'UDP ho fatto così che ne pensate?
... |
31-03-2005 14:34 |
|
 |
Vale |
.illuminato.
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline
Edit | Report | IP: Logged |
io per l'UDP ho fatto così che ne pensate?
import java.io.*;
import java.net.*;
public class ServerUDP{
private static DatagramSocket ss= null;
public static void main(String[] args){
try{
ss = new DatagramSocket(12000);
while (true){
byte[] recvData = new byte[1024];
DatagramPacket recvPacket = new DatagramPacket(recvData,recvData.length);
ss.receive(recvPacket);
ServerThreadUDP t= new ServerThreadUDP(ss,recvPacket);
t.start();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.io.*;
import java.net.*;
public class ClientUDP{
private static DatagramSocket socket;
private static InputStreamReader reader;
private static BufferedReader myInput;
private static String LAFRASE= "La frase e':";
public static void main(String[] args){
try{
socket = new DatagramSocket();
InetAddress ipaddress=InetAddress.getByName("localhost");
System.out.println("inserisci la frase:");
reader = new InputStreamReader(System.in);
myInput = new BufferedReader(reader);
byte[] sendData = new byte[1024];
byte[] recvData = new byte[1024];
String frase= LAFRASE+myInput.readLine();
sendData=frase.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipaddress, 12000);
socket.send(sendPacket);
DatagramPacket recvPacket = new DatagramPacket(recvData, recvData.length);
socket.receive(recvPacket);
int c;
String recfrase="";
for (int i=0; (c=recvPacket.getData()[i])!=0; i++)
recfrase+= (char) c;
System.out.println("La frase in maiuscolo è :"+recfrase.substring(LAFRASE.length())+" di lunghezza: "+ (recfrase.length()-LAFRASE.length()));
String lung= "La lunghezza e'"+(recfrase.length()-LAFRASE.length())+"\n";
sendData= lung.getBytes();
sendPacket.setData(sendData);
sendPacket.setLength(sendData.length);
socket.send(sendPacket);
socket.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.DatagramSocket;
public class ServerThreadUDP extends Thread {
private static DatagramSocket socket;
private static byte[] recvData;
private static byte[] sendData;
private static DatagramPacket recvPacket;
public ServerThreadUDP(DatagramSocket s, DatagramPacket recvPacket){
socket = s;
this.recvPacket = recvPacket;
recvData= new byte[1024];
sendData= new byte[1024];
}
public void run(){
try{
int c;
String frase="";
for (int i=0 ; (c=recvPacket.getData()[i])!=0; i++)
frase += (char) c;
System.out.println(frase);
InetAddress ipaddress =recvPacket.getAddress();
int porta = recvPacket.getPort();
frase= frase.toUpperCase();
sendData = frase.getBytes();
DatagramPacket sendPacket= new DatagramPacket(sendData, sendData.length, ipaddress, porta);
socket.send(sendPacket);
}catch(Exception e){
e.printStackTrace();
}
}
}
|
31-03-2005 14:34 |
|
|
|  |
 |
papousek |
grazie del codice....mi ci vorra un secolo per dec ... |
31-03-2005 14:42 |
|
 |
papousek |
Prisoner

Registered: Jan 2005
Posts: 1562 (0.21 al dì)
Location: Sona
Corso: Dottore dal 2006
Anno: End
Time Online: 16 Days, 7:11:58 [...]
Status: Offline
Edit | Report | IP: Logged |
grazie del codice....mi ci vorra un secolo per decriptarlo....
nota di redazione...nn c ho capito na randazza di mazza...
__________________
Break Out
Last edited by papousek on 31-03-2005 at 14:50
|
31-03-2005 14:42 |
|
|
|  |
 |
francesco2 |
é lo stesso esercizio che ha fatto Flavia però i ... |
31-03-2005 14:43 |
|
 |
francesco2 |
.illuminato.
Registered: Jan 2004
Posts: 176 (0.02 al dì)
Location: biella
Corso: comunicazione digitale
Anno: 3
Time Online: 1 Day, 12:42:42 [...]
Status: Offline
Edit | Report | IP: Logged |
é lo stesso esercizio che ha fatto Flavia però in Udp?
Grazie!
__________________
r
|
31-03-2005 14:43 |
|
|
|  |
 |
UZI |
guarda, io ti spiego alcune mie considerazioni, p ... |
31-03-2005 14:47 |
|
 |
UZI |
free pain dispenser

Registered: Mar 2003
Posts: 2211 (0.27 al dì)
Location: monza - troppi fighetti
Corso: com. dig.
Anno: Dottor Morte
Time Online: 14 Days, 4:46:06: [...]
Status: Offline
Edit | Report | IP: Logged |
guarda, io ti spiego alcune mie considerazioni, prendile con le pinze perchè non fanno riferimento a materiale didattico (che non c'è, o quantomeno non i è stato fornito) ma sono frutto di miei ragionamenti.
nel codice che ho postato io, creo una datagramsocket che ha l'unico scopo di stare in ascolto e ricevere i pacchetti, poi al thread passo non il pacchetto ma i dati che contiene e l'indirizzo di provenienza. questo perchè ho paura che sennò faccia casino, in quanto quando passi il pacchetto non passi una sua copia ma proprio l'area di memoria che lo contiene... quindi alla fine tutti i thread si troverebbero a la vorare sullo stesso buffer e questo non è a mio avviso consigliabile.
cmq, non ho fatto test approfonditi.
__________________
those who test will find a bullet in they chest
put ta rest
by a brotha who was hopeless
grow up broke on tha rope of insanity
how many pistols smoking coming from a broken family
|
31-03-2005 14:47 |
|
|
|  |
 |
urcodiaz |
quindi devo usare la classe engine? ... |
31-03-2005 14:50 |
|
 |
urcodiaz |
*incredibile*
Registered: Jan 2003
Posts: 83 (0.01 al dì)
Location:
Corso: Comunicazione Digitale
Anno: 3°
Time Online: 1 Day, 1:26:51 [...]
Status: Offline
Edit | Report | IP: Logged |
quindi devo usare la classe engine?
__________________

|
31-03-2005 14:50 |
|
|
|  |
 |
yeah |
[quote=Vale]
... |
31-03-2005 14:51 |
|
 |
yeah |
.grande:maestro.

Registered: Nov 2003
Posts: 1644 (0.21 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline
Edit | Report | IP: Logged |
Originally posted by Vale
io per l'UDP ho fatto così che ne pensate?
Che potevi mettere qualche commento 
__________________
?
|
31-03-2005 14:51 |
|
|
|  |
 |
Vale |
e si effettivamente... :-) ... |
31-03-2005 14:54 |
|
 |
Vale |
.illuminato.
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline
Edit | Report | IP: Logged |
e si effettivamente... :-)
|
31-03-2005 14:54 |
|
|
|  |
 |
All times are GMT. The time now is 03:43. |
|
|
 |
|
 |
|
|
|  |
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
|
|
|
|
|
|