Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi N - Z > Reti di calcolatori > [info] Appello 1 Aprile
Pages (10): « First ... « 2 3 4 5 [6] 7 8 9 10 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
UZI
free pain dispenser

User info:
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

Post actions:

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
Click Here to See the Profile for UZI Click Here to See the Blog of UZI Click here to Send UZI a Private Message Find more posts by UZI Add UZI to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
urcodiaz
*incredibile*

User info:
Registered: Jan 2003
Posts: 83 (0.01 al dì)
Location:
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 1:26:51 [...]
Status: Offline

Post actions:

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!!

__________________
:boing:

31-03-2005 12:19
Click Here to See the Profile for urcodiaz Click here to Send urcodiaz a Private Message Find more posts by urcodiaz Add urcodiaz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
UZI
free pain dispenser

User info:
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

Post actions:

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
Click Here to See the Profile for UZI Click Here to See the Blog of UZI Click here to Send UZI a Private Message Find more posts by UZI Add UZI to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
francesco2
.illuminato.

User info:
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

Post actions:

Edit | Report | IP: Logged

Grazieee UZI

__________________
r

31-03-2005 12:30
Click Here to See the Profile for francesco2 Click here to Send francesco2 a Private Message Find more posts by francesco2 Add francesco2 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
papousek
Prisoner

User info:
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

Post actions:

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
Click Here to See the Profile for papousek Click here to Send papousek a Private Message Find more posts by papousek Add papousek to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
foxinho
.arcimaestro.

User info:
Registered: Oct 2003
Posts: 254 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 2 Days, 14:41:59 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

la vedo grigia domani...:(:(:(

31-03-2005 14:14
Click Here to See the Profile for foxinho Click here to Send foxinho a Private Message Find more posts by foxinho Add foxinho to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Vale
.illuminato.

User info:
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for Vale Click here to Send Vale a Private Message Find more posts by Vale Add Vale to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
francesco2
.illuminato.

User info:
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

Post actions:

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
Click Here to See the Profile for francesco2 Click here to Send francesco2 a Private Message Find more posts by francesco2 Add francesco2 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Vale
.illuminato.

User info:
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline

Post actions:

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
Click Here to See the Profile for Vale Click here to Send Vale a Private Message Find more posts by Vale Add Vale to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
papousek
Prisoner

User info:
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

Post actions:

Edit | Report | IP: Logged

grazie del codice....mi ci vorra un secolo per decriptarlo....:D

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
Click Here to See the Profile for papousek Click here to Send papousek a Private Message Find more posts by papousek Add papousek to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
francesco2
.illuminato.

User info:
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

Post actions:

Edit | Report | IP: Logged

é lo stesso esercizio che ha fatto Flavia però in Udp?

Grazie!:)

__________________
r

31-03-2005 14:43
Click Here to See the Profile for francesco2 Click here to Send francesco2 a Private Message Find more posts by francesco2 Add francesco2 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
UZI
free pain dispenser

User info:
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

Post actions:

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
Click Here to See the Profile for UZI Click Here to See the Blog of UZI Click here to Send UZI a Private Message Find more posts by UZI Add UZI to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
urcodiaz
*incredibile*

User info:
Registered: Jan 2003
Posts: 83 (0.01 al dì)
Location:
Corso: Comunicazione Digitale
Anno:
Time Online: 1 Day, 1:26:51 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

quindi devo usare la classe engine?

__________________
:boing:

31-03-2005 14:50
Click Here to See the Profile for urcodiaz Click here to Send urcodiaz a Private Message Find more posts by urcodiaz Add urcodiaz to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
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

Post actions:

Edit | Report | IP: Logged

Originally posted by Vale

io per l'UDP ho fatto così che ne pensate?

Che potevi mettere qualche commento :asd:

__________________
?

31-03-2005 14:51
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Vale
.illuminato.

User info:
Registered: Jul 2002
Posts: 230 (0.03 al dì)
Location:
Corso:
Anno:
Time Online: 3 Days, 19:48:50 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

e si effettivamente... :-)

31-03-2005 14:54
Click Here to See the Profile for Vale Click here to Send Vale a Private Message Find more posts by Vale Add Vale to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 03:43.    Post New Thread    Post A Reply
Pages (10): « First ... « 2 3 4 5 [6] 7 8 9 10 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

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
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.167 seconds (63.50% PHP - 36.50% MySQL) con 23 query.