Tuesday 15 March 2011

c - single char from socket, one at a time -



c - single char from socket, one at a time -

i'm working on little telnetish game in c text based gui. need single char socket without '\n' needed can command on keys.

i have

16 char buffer[256]; 17 bzero(buffer,256); 18 n = read(sock,buffer,255);

but read() accepts char *.

recv() improve still need pass '\n' it.

i found way turn off telnet line mode, that's not working me, and/or don't understand it.

write(s,"\377\375\042\377\373\001",6);

from have found on forum there might way ncurses.

what best way it?

what i'm at

12 void doprocessing (int sock) 13 { 14 int n; 15 int i; 16 char buffer; 17 n = recv(sock,&buffer,1,0); 18 if (n < 0) 19 { 20 perror("error reading socket"); 21 exit(1); 22 } 23 printf("msg: %c\n",buffer); 24 n = write(sock,"msg sent\n",18); 25 }

read() accepts char *.

char * , char[] equivalent in c, purpose. didn't seek it.

recv() improve still need pass '\n' it.

no, recv() identical read() sockets unless 4th argument non-zero, , don't need pass \n it.

i found way turn off telnet line mode, that's not working me, and/or don't understand it.

write(s,"\377\375\042\377\373\001",6);

this iac linemode (255 253 36), shouldn't sent @ client, followed iac echo (255 251 1). right command iac linemode (255 251 36) or "\377\373\042", , there reply iac linemode (255 253 36 or "\377\375\042") iac linemode server gives permission begin negotiation of linemode. suggest study rfc1116 farther details, rather complicated, , needs read in conjunction rfc854 , others.

c sockets char

No comments:

Post a Comment