Bonjour tout le monde !!
Je suis en train de développer une application de type client/serveur utilisant le protocole TCP. Mon serveur est développé en c#, et le client, en java.
Malheureusement, tout ce ne passe pas comme prévu : mon appli ne veut/peut se connecter au serveur.
Code client (java) :
Info :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Socket s = null; try { System.out.println("Connecting ..."); s = new Socket(name_server, 35555); System.out.println("Connected"); } catch (Exception ex) { System.out.println("Erreur connexion : " + ex.getCause() + " // " + ex.getMessage()); }
- name_server stocke le nom NetBios du serveur
- le catch me renvoie :
---------------------------------------------------Erreur connexion : null // null
Code serveur (c#)
Quelqu'un aurait une idée du pourquoi du comment ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 // display the server's name MessageBox.Show("Server Name : " + Environment.MachineName.ToString()); // Set the TcpListener on port 35555. Int32 port = 35555; IPAddress localAddr = IPAddress.Any; // TcpListener server = new TcpListener(port); server = new TcpListener(localAddr, port); // Start listening for client requests. server.Start(); // Buffer for reading data Byte[] bytes = new Byte[256]; String data = null; // Enter the listening loop. while (true) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Connected!"); data = null; // Get a stream object for reading and writing NetworkStream stream = client.GetStream(); int i; // Loop to receive all the data sent by the client. while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); Console.WriteLine("Received: {0}", data); // Process the data sent by the client. data = data.ToUpper(); byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); // Send back a response. stream.Write(msg, 0, msg.Length); Console.WriteLine("Sent: {0}", data); } // Shutdown and end connection client.Close(); }
Merci d'avance !
Partager