cs_felouss
Messages postés6Date d'inscriptiondimanche 16 avril 2006StatutMembreDernière intervention26 juin 2006
-
26 juin 2006 à 15:44
sheorogath
Messages postés2448Date d'inscriptionsamedi 21 février 2004StatutModérateurDernière intervention29 janvier 2010
-
26 juin 2006 à 18:55
bonjour,j ai un probleme pour envoyer un gros fichier via UDP,udp ne permet l envoie de paquet > 65kilo,pour cela du coté serveur j ai decoupé le fichier en plusieurs paquet et je l ai mit dans un tableau de string pour l envoyer,mais le probleme se pose au niveau du client,il ne recoit que le 1er paquet apres ca blok!!ben voila si klk1 peut m aider,ci dessous le code du serveur et du client,merci d avance!
public static void main(String arg[])
{
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
// chooser.addChoosableFileFilter(FILE_FILTER);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {//selection valide
if (chooser.getSelectedFile()== null ) return; // user pressed Cancel
File theFile = new File(chooser.getCurrentDirectory(),
chooser.getName(chooser.getSelectedFile()) );
theText = "";
try {
FileReader fr = new FileReader(theFile);
char charar[] = new char[(int)theFile.length()];
fr.read(charar);
theText = String.valueOf(charar);
String ligne; System.out.println("zzz");
BufferedReader entree = new BufferedReader(fr);
do{ ligne=entree.readLine(); System.out.println("kkk");
if(ligne!=null)
System.out.println("ligne"); System.out.println(ligne);}
while (ligne!=null);
entree.close();
fr.close();
}
catch ( FileNotFoundException excpt0 ) {}
catch ( IOException excpt1 ) {}
//currDirectory=(String)chooser.getCurrentDirectory();
/* currFileName=chooser.getName(chooser.getSelectedFile());
statusBar.setText(currFileName+ " ...ouvert");
zone.setText("");
String contenu=String.valueOf(theText);
Write_text(contenu,0);
dirty=false;updateCaption();}*/
}
//System.out.println(theText);
try{
size=theText.length();
System.out.println("the size is : "+size); //System.out.println(theText);
// c3=size/65000;
// System.out.println(c3);
int c3=size/65000;//System.out.println(c3);
int c4=c3+1;System.out.println("Decoupage en : "+c4);
int c5=c3*65000;//System.out.println("le chifre est :"+c5);
String [] tab = new String [10000000];
//for(int i=0;i<tab.length;i++)
int i=0;
int k=0;
while(i<c4)
{
String aa[]= new String[3000];
int f = k + 65000 ;
System.out.println("size of f: "+f);
if (f>size)
{
f=size-k;
System.out.println("size of f smaller: "+f);
int help = size;
tab[i]= theText.substring(k,help);
}//System.out.println(tab.length);
//System.out.println(theText);
//c3=size/65000;
//System.out.println(c3);
else {
tab[i]= theText.substring(k,f);
}
;//System.out.println(tab[i]);
k=k+65000;
//i++; }while(i<c4);
buff = new byte[200];
String s="Message a envoyer";
//byte data[] = s.getBytes();
// for(int j=0;j<tab.length;j++){
data = tab[i].getBytes(); i++;
System.out.println("size of i: "+i);
Ip = InetAddress.getByName("224.0.1.20");
p = new DatagramPacket(data,data.length,Ip,8082);
serv = new MulticastSocket();
c = new MulticastSocket(8082);
rec = new DatagramPacket(buff,buff.length);
// System.out.println(theText);
String re = new String(rec.getData());
System.out.println(re);
//}
} //while(i<=c4);
//System.out.println(theText);
// serv.close();
}
catch(IOException e){System.out.println(e);}
}
public static String theText;
//public static JFileChooser chooser = new JFileChooser();
//public static File theFile = new File(chooser.getCurrentDirectory(),chooser.getName(chooser.getSelectedFile()) );
public static int size;
//public static int c4=size;
//public static int c3=c4/65000;
//public static String [] tab = new String [c3];
public static byte data[];
public static byte buff[];
public static InetAddress Ip; // InetAddress.getByName("224.0.1.20");
public static DatagramPacket p; //= new DatagramPacket(data,data.length,Ip,8082);
public static MulticastSocket serv;// = new MulticastSocket();
public static MulticastSocket c;// = new MulticastSocket(8082);
public static DatagramPacket rec;// = new DatagramPacket(buff,buff.length);
}
//////////////////////////////////////
le code du client
///////////////////////////
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
class MulticastClient
{
public static void main(String arg[])
{
try{
String a = "ameur ";
String a1 = "tu est trop fort ";
a=a.concat(a1);
System.out.println(a);
// Object o;
//File objFich = new File ("amr.txt");
//DataOutputStream sortie = new DataOutputStream(new FileOutputStream(objFich));
//o=objFich;
int i=0;
while(i<10)
{ String mess = "fred t es trop B... ";
byte buff[] = mess.getBytes();
String host = "224.0.1.20";
byte data[] = new byte[200];
Ip = InetAddress.getByName("224.0.1.20");
p = new DatagramPacket(data,data.length);
rec = new DatagramPacket(buff,buff.length,Ip,8082);
serv = new MulticastSocket(8082);
String s = new String(p.getData());
mm=mm.concat(s);
System.out.println(mm);i++;
try{
File file = new File("a.txt");
FileWriter out = new FileWriter(file,true);
//int i=sortie.lastIndexOf('%');
//if(k==0)if(i!=-1)sortie=sortie.substring(0,i);
out.write(mm);
out.close();
}catch (IOException e) {}
serv.send(rec);
serv.close(); }//fin du while
}
catch(IOException e){System.out.println(e);}
}
public static String mm = "";
public static byte data[];
public static byte buff[];
public static InetAddress Ip; // InetAddress.getByName("224.0.1.20");
public static DatagramPacket p; //= new DatagramPacket(data,data.length,Ip,8082);
public static MulticastSocket serv;// = new MulticastSocket();
public static MulticastSocket c;// = new MulticastSocket(8082);
public static DatagramPacket rec;