Results 1 to 1 of 1
- 10-18-2010, 05:18 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Problem when communicating java server and C client application
Hi all, I have the following problem:
My server sends the string str="1 2 4 dds \n" continuously to a C++ client.Here is the java code of the server:
Here is the partial C code of the client:Java Code:private class SendingThread implements Runnable{ public Socket s; public DataOutputStream oo; public ObjectInputStream oi; ////private QueryTransferObject q; boolean connected; public SendingThread() { super(); // TODO Auto-generated constructor stub } @Override public void run() { try { Socket s = new Socket("137.132.153.60",8080); connected = true; byte[] str; str=new byte[25600]; str="1 2 4 dds \n".getBytes(); while (connected) { try { ObjectOutputStream oo=new ObjectOutputStream(s.getOutputStream()); oo.write(str); oo.flush(); System.out.print("send \n"); // Log.d("SendingThread", "C: Send data object finished."); // connected = false; Thread.sleep(2000); } catch (Exception e) { // Log.e("SendingThread", "S: Error", e); } }
The client keeps display this result:Java Code:if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); while(1) { printf("I am here\n"); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = read(newsockfd,buffer,255); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); }
I am here
Here is the message: �
I am here
Here is the message: w
1 2 4 dds
It seems that the message is not received correctly. Can anyone give some insight on how to fix it ? Thank you!
Similar Threads
-
Java Socket server with C client problem
By rnvrnv in forum NetworkingReplies: 6Last Post: 11-09-2010, 12:47 AM -
Java Server & C# client communicating through sockets
By yukijocelyn in forum NetworkingReplies: 0Last Post: 09-05-2008, 10:05 PM -
Communicating Java Server and C client using char buffer
By tryit0704 in forum NetworkingReplies: 2Last Post: 08-27-2008, 03:24 PM -
Identify Client in Socket Client Server Application
By masadjie in forum NetworkingReplies: 1Last Post: 12-20-2007, 09:18 AM -
Simple example Client Server Application
By ferosh in forum NetworkingReplies: 1Last Post: 04-01-2007, 10:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks