• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send '-1' via a socket to a c program  RSS feed

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a c program (on linux) which read an int from a socket:

int readID = 0;
memset(line, 0x0, LINE_ARRAY_SIZE);
while ( (recv(connectSocket, line, MAX_MSG, 0) > 0) ) {

int readSdpID = 0;

memcpy (&readID, line, sizeof (int));

printf ("readID %d \n", readID);
}

My question is how can I send a value '-1' in Java?

I try using this:
int errorCode = -1;
InputStream is = socket.getInputStream();

wr.write(errorCode);
wr.flush();


But the C side reads back a number ' 12435439', can you please tell me how can I change the Java side to send out a '-1' (integer)?

Thank you
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolve my problem. Sorry for the confusion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!