Java client/serveur
stephe
-
informaticienSAP Messages postés 119 Date d'inscription Statut Membre Dernière intervention -
informaticienSAP Messages postés 119 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai un problème car je bloque :
le client:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
import java.net.*;
import java.io.*;
public class ServeurTCP {
Display display = new Display();
Shell shell = new Shell(display);
Group group = new Group(shell,SWT.CENTER);
Text t=new Text(group,SWT.LEFT);
Text t1 =new Text(group,SWT.LEFT);
Button button = new Button(group,SWT.CENTER);
Label label = new Label (shell,SWT.CENTER);
String message = new String ();
public ServeurTCP() {
shell.setSize(400, 400);
label.setSize(80, 40);
label.setLocation(150, 330);
label.setText("*Serveur*");
group.setBounds(10, 10, 360, 300);
t.setSize(340, 150);
t.setLocation(9, 15);
t1.setSize(190, 80);
t1.setLocation(10,200);
button.setSize(100, 80);
button.setLocation(250, 200);
button.setText("*Envoyer*");
shell.open();
Listener listener = new Listener(){
public void handleEvent (Event event){
try{
recevoire();
}catch(Exception e1){System.out.println("Exception :"+e1);
}
}
};
button.addListener(SWT.Selection, listener);
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
public void recevoire () throws Exception{
ServerSocket ecoute= new ServerSocket(5432);
Socket service= (Socket)null;
String message1 = new String();
String message2 = new String();
while(message1!=null)
{
t.append(message1+message2);
service=ecoute.accept();
BufferedReader in=new BufferedReader (new InputStreamReader(service.getInputStream()));
message1=in.readLine();
service.close();
}}
public static void main(String args[])throws Exception{
new ServeurTCP ();}}
le serveur
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import java.net.*;
import java.io.*;
public class ClientTCP {
public ClientTCP () {
Display display= new Display();
Shell shell= new Shell(display);
shell.setText("Client");
shell.setSize(750,500);
shell.setBackground(new Color(display,255,255,255));
Group group= new Group(shell, SWT.CENTER);
group.setSize(720,190);
group.setLocation(05,265);
group.setBackground(new Color(display,255,255,255));
Group group2= new Group(shell, SWT.CENTER);
group2.setBackground(new Color(display, 255,255,255));
group2.setLocation(05,02);
group2.setSize(725,255);
Text text= new Text(group, SWT.LEFT);
text.setSize(550,150);
text.setLocation(10,25);
text.setBackground(new Color(display,197,240,245));
Button button= new Button(group, SWT.CENTER);
button.setText("Envoyer");
button.setSize(100,100);
button.setLocation(580,50);
Label label= new Label(group2, SWT.CENTER);
label.setSize(700,240);
label.setLocation(06, 10);
label.setBackground(new Color (display,197,240,245));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch());
display.sleep();
}
display.dispose();
}
public static void main(String [] args) throws Exception {
new ClientTCP();
String message= "Hello Mira. Tu va bien??";
for(int j=0;j<100;j++) {
long start= System.currentTimeMillis();
for (int i=0;i<message.length();i++)
{
Socket s= new Socket("localhost",5432);
OutputStream os= s.getOutputStream();
os.write(message.charAt(i));
s.close();
}
long end= System.currentTimeMillis();
System.out.println("TCP: Message envoyé"+j+": temps d'émmission= "+("end+start")+"ms");
}
}
}
Quelqu'un pourrait m'aider, merci d'avance à tous
24 minutes
j'ai un problème car je bloque :
le client:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
import java.net.*;
import java.io.*;
public class ServeurTCP {
Display display = new Display();
Shell shell = new Shell(display);
Group group = new Group(shell,SWT.CENTER);
Text t=new Text(group,SWT.LEFT);
Text t1 =new Text(group,SWT.LEFT);
Button button = new Button(group,SWT.CENTER);
Label label = new Label (shell,SWT.CENTER);
String message = new String ();
public ServeurTCP() {
shell.setSize(400, 400);
label.setSize(80, 40);
label.setLocation(150, 330);
label.setText("*Serveur*");
group.setBounds(10, 10, 360, 300);
t.setSize(340, 150);
t.setLocation(9, 15);
t1.setSize(190, 80);
t1.setLocation(10,200);
button.setSize(100, 80);
button.setLocation(250, 200);
button.setText("*Envoyer*");
shell.open();
Listener listener = new Listener(){
public void handleEvent (Event event){
try{
recevoire();
}catch(Exception e1){System.out.println("Exception :"+e1);
}
}
};
button.addListener(SWT.Selection, listener);
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
public void recevoire () throws Exception{
ServerSocket ecoute= new ServerSocket(5432);
Socket service= (Socket)null;
String message1 = new String();
String message2 = new String();
while(message1!=null)
{
t.append(message1+message2);
service=ecoute.accept();
BufferedReader in=new BufferedReader (new InputStreamReader(service.getInputStream()));
message1=in.readLine();
service.close();
}}
public static void main(String args[])throws Exception{
new ServeurTCP ();}}
le serveur
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import java.net.*;
import java.io.*;
public class ClientTCP {
public ClientTCP () {
Display display= new Display();
Shell shell= new Shell(display);
shell.setText("Client");
shell.setSize(750,500);
shell.setBackground(new Color(display,255,255,255));
Group group= new Group(shell, SWT.CENTER);
group.setSize(720,190);
group.setLocation(05,265);
group.setBackground(new Color(display,255,255,255));
Group group2= new Group(shell, SWT.CENTER);
group2.setBackground(new Color(display, 255,255,255));
group2.setLocation(05,02);
group2.setSize(725,255);
Text text= new Text(group, SWT.LEFT);
text.setSize(550,150);
text.setLocation(10,25);
text.setBackground(new Color(display,197,240,245));
Button button= new Button(group, SWT.CENTER);
button.setText("Envoyer");
button.setSize(100,100);
button.setLocation(580,50);
Label label= new Label(group2, SWT.CENTER);
label.setSize(700,240);
label.setLocation(06, 10);
label.setBackground(new Color (display,197,240,245));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch());
display.sleep();
}
display.dispose();
}
public static void main(String [] args) throws Exception {
new ClientTCP();
String message= "Hello Mira. Tu va bien??";
for(int j=0;j<100;j++) {
long start= System.currentTimeMillis();
for (int i=0;i<message.length();i++)
{
Socket s= new Socket("localhost",5432);
OutputStream os= s.getOutputStream();
os.write(message.charAt(i));
s.close();
}
long end= System.currentTimeMillis();
System.out.println("TCP: Message envoyé"+j+": temps d'émmission= "+("end+start")+"ms");
}
}
}
Quelqu'un pourrait m'aider, merci d'avance à tous
24 minutes
A voir également:
- Java client/serveur
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Cybera client - Télécharger - Divers Réseau & Wi-Fi
- Changer serveur dns - Guide
- Eclipse java - Télécharger - Langages