Hi i wrote a server for a simple chat program and im having a little trouble with my buffer that im sending back and forth. My buffer takes in what the person says and writes it to the other person. But im having trouble with over lapping when i say something shorter then the last statment to the other person. I have tried searching for a null character at the end of each buffer but for some reason thats not working here is my code that is having the problem. Each time i write it needs to be the exact size of the character array that is being sent and strlen() isn't working for some reason. if you need any more information just ask me.
Code:
{
char buf[] = "Start chatting now\n";
write( io_sd, buf, strlen( buf ) );
write( io_sd2, buf, strlen( buf ) );
do
{
read( io_sd, buf_io, cap);
for(i=0; i<cap; i++)
{
tmp[i] = buf_io[i];
count++;
if(tmp[i] == '\0')
{
break;
}
}
printf("%d", count);
write( io_sd2, buf_io, count );
read( io_sd2, buf_io, cap );
for(i=0; i<cap; i++)
{
tmp[i] = buf_io[i];
count++;
if(tmp[i] == '\0')
{
break;
}
}
printf("%d", count);
write( io_sd, buf_io, count );
}while(1);
}
here are some test runs
Code:
Person #1
[ ~]$ telnet localhost 15003
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Start chatting now
test
this is a longer test
shorter test
Person #2
[ ~]$ telnet localhost 15003
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Start chatting now
test
this is a longer test
shorter test
er test
Mab8v¸ b8èÄAb8C