Salut à tous,
je (crise) un peu, j'ai une application client/serveur en JAVA qui tourne très bien,
la partie de cette appli fonctionne en TCP :

voici la fonction qui recupere les messages en byte par byte en java

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
 
	/**
         * reception de bytes
         * @return
         * @throws IOException
         */
	public byte[] readBytes() throws IOException {
		InputStream in = s.getInputStream();
		DataInputStream dis = new DataInputStream(in);
 
		int len = dis.readInt();
		byte[] data = new byte[len];
 
		if(len>0) {
			dis.readFully(data);
		}
		return data;
	}
celle ci fonctionne très bien en JAVA,

mais en C , c'est tout autre chose, mon client se connecte sur mon serveur, jusqu'ici très bien, mais rien ne parvient a être envoyé, j'utilise la fonction :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
  char *buffer2 = "testnom\r\n";
  send(sock,buffer2,sizeof(buffer),0);
j'ai des tests sur chacunes des fonctions importante en C qui me retourne un message d'erreur en cas d'echec, et toutes les fonctions "fonctionnent parfaitment".

Vous voyez autre chose ?


mon code pour l'instant assez sale en C
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
 
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
 
#define SERVEURNAME "127.0.0.1"
 
int sock = -1;
 
void
main (void)
{
 
  char *server_name = SERVEURNAME;
  struct sockaddr_in serverSockAddr;
  struct hostent *serverHostEnt;
  long hostAddr;
  long status;
  char buffer[512];
 
 
 
  bzero (&serverSockAddr, sizeof (serverSockAddr));
  hostAddr = inet_addr (SERVEURNAME);
  if ((long) hostAddr != (long) -1)
    bcopy (&hostAddr, &serverSockAddr.sin_addr, sizeof (hostAddr));
  else
    {
      serverHostEnt = gethostbyname (SERVEURNAME);
      if (serverHostEnt == NULL)
	{
	  printf ("ServerHost ERROR\n");
	  return (-1);
	}
 
      bcopy (serverHostEnt->h_addr, &serverSockAddr.sin_addr,
	     serverHostEnt->h_length);
    }
  serverSockAddr.sin_port = htons (50987);
  serverSockAddr.sin_family = AF_INET;
 
/* creation de la socket */
 
  sock = createTCP();
/* requete de connexion */
  if (connect (sock,
	       (struct sockaddr *) &serverSockAddr,
	       sizeof (serverSockAddr)) < 0)
    {
      printf ("Connection ERROR\n");
      return (-1);
    }
  printf("connexion success\n");
/* envoie de donne et reception */
  char *buffer2 = "testnom\0";
  send(sock,buffer2,sizeof(buffer+1),0);
  printf("emmssion du nom terminée");
  read (sock, buffer, 512);
  printf (buffer);
/* fermeture de la connection */
 
  close (sock);
}
 
 
 
//file mainfun.c
int createTCP() {
  if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
    {
      printf ("creation socket ERROR\n");
      return (-1);
    }
  return sock;
}