Socket ne reçoit pas le message
Bonjour
je mets au point un petit systeme de chat entre mes 2 pcs (un windows et un linux) en utilisant les sockets
J'ai fais la redirection des ports sur ma bbox
Mon code pour serveursocket sur linux
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import java.io.*;
import java.net.*;
import java.net.InetAddress;
public class ServeurSocket {
public static void main(String[] args) {
/*
for(int port = 1; port <= 65535; port++){
try {
ServerSocket sSocket = new ServerSocket(port);
System.out.println("Le port " + port + " est libre ! ");
} catch (IOException e) {
System.err.println("Le port " + port + " est déjà utilisé ! ");
}
}*/
//String IP = "192.168.1.46";
String IP = "192.168.1.50";
int fileAttente = 100;
try {ServerSocket sSocket = new ServerSocket(45000, fileAttente, InetAddress.getByName(IP));
System.out.println("Server is opened!");
//try {ServerSocket sSocket = new ServerSocket(63356);
while(true){
Socket soc=sSocket.accept();
InputStream flux =soc.getInputStream();
BufferedReader entree= new BufferedReader( new InputStreamReader(flux));
String message=entree.readLine();
System.out.println(message);
}
}
catch (IOException e) {
System.err.println(e);
System.exit(1);
}
}
} |
sur mon windows le script client
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| import java.io.*;
import java.net.*;
import java.util.*;
public class Client
{
public static void main(String[] args) throws IOException {
String hote="192.168.1.50";
int port=45000;
try{Socket soc =new Socket(hote,port);}
catch(IOEXception(e){
System.err.println(e);
}
OutputStream flux= soc.getOutputStream();
OutputStreamWriter sortie= new OutputStreamWriter (flux);
Scanner sc = new Scanner(System.in);
// System.out.println("Write a message : ");
String str = sc.nextLine();
sortie.write(str);
sortie.flush();
}
} |
Quand je transmet un String de mon pc client vers mon pc serveur j'ai un message d'erreur preuve qu'il se passe quelque chose
java.net.SocketExeption:connection reset
J'ai épluché pas mal de post sur cette erreur impossible de trouver la solution
Merci pour votre aide