I'm trying to get a C99 client to communicate with a Java server. However the data being received by the Java server is not the same as the data that was transmitted. (ie. @x�@Ófl/ú.��@¨�����������������Û¢ÁBp‘ˇ¡`Ôfl/)
I've contemplated that it's an encoding issue however I've hit a brick wall. I've tried testing the two programs to conclude that the Java server is able to communicate with a Java client and the C client is able to communicate with a C server.
However I cannot get the Java server to communicate with a C client.
Java code:
serverSocket = new ServerSocket(port);
Socket sock = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String inputString = in.readLine();
System.out.println(inputString);
C code:
struct sockaddr_in sin;
struct hostent *host;
host = gethostbyname(hostname);
bzero(&(sin.sin_zero),8);
sin.sin_port = htons(port);
sin.sin_addr = *((struct in_addr *)host->h_addr);
sin.sin_family = AF_INET;
sock = socket(AF_INET, SOCK_STREAM, 0);
if(connect(sock, (struct sockaddr *)&sin,sizeof(struct sockaddr_in)) == -1)
...
send(sock, &message, strlen(message)+1, 0);
EDIT: I've tried sending the word 'TEST' between the two hosts without success.
FIXED: I had an ampersand in front of the message variable as I was passing it.
Should have been:
send(sock, message, strlen(message)+1, 0);