Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************************
- //
- // Petr Olivka (c) 03/2013 pro projekt do predmetu OSY.
- // Viz. http://poli.cs.vsb.cz/edu/osy
- //
- // Ukazka kodu pro prijem a odesilani zprav.
- //
- // Prijem a odesilani zprav si bude kazdy ve svem projektu implementovat sam!
- //
- //***************************************************************************
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <stdarg.h>
- #include <time.h>
- #include <sys/socket.h>
- #include <sys/param.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <errno.h>
- #include <netdb.h>
- #include "msg_io.h"
- int send_proto_msg( int handle, char type, int NN, const char *text ) {
- char buffer[256];
- int len=sprintf (buffer, "%c%02d:%s\n", type, NN, text);
- m_print( M_DEBUG, "send %d %s",len,buffer);
- int ret=write(handle, buffer, len);
- return ret;
- }
- int recv_proto_msg( int handle, char *type, int *NN, char *text ) {
- char buffer[256];
- int ret=read(handle,buffer,256);
- buffer[ret]='\0';
- m_print( M_DEBUG,"recv1 %d %s",ret,buffer);
- if(ret<=0) return ret;
- *type=buffer[0];
- buffer[0]='0';
- char * pch;
- pch = strtok (buffer,":");
- *NN=atoi(pch);
- pch = strtok (NULL,":");
- strcpy(text,pch);
- sprintf(buffer, "%c%02d:%s\n", *type, *NN, text);
- m_print( M_DEBUG,"recv2 %s",buffer);
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment