73int main(
int argc,
char *argv[])
75 int sockfd, portno, n;
76 struct sockaddr_in serv_addr;
86 MSG_ERR(
"main: Can't read dpid's port number\n");
90 sockfd = socket(AF_INET, SOCK_STREAM, 0);
92 error(
"ERROR opening socket");
93 memset(&serv_addr, 0,
sizeof(serv_addr));
94 serv_addr.sin_family = AF_INET;
95 serv_addr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
97 serv_addr.sin_port = htons(portno);
98 if (connect(sockfd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr)) < 0)
99 error(
"ERROR connecting");
101 snprintf(buffer,
sizeof(buffer),
"<cmd='auth' msg='%s' '>",
SharedKey);
102 n = write(sockfd, buffer, strlen(buffer));
104 error(
"ERROR writing to socket");
106 if (strcmp(argv[1],
"stop") == 0) {
108 }
else if (strcmp(argv[1],
"register") == 0) {
110 }
else if (strcmp(argv[1],
"chat") == 0) {
111 printf(
"Please enter the message: ");
112 memset(buffer,0,256);
113 if (fgets(buffer,255,stdin) == NULL)
114 MSG_ERR(
"dpidc: Can't read the message\n");
116 MSG_ERR(
"main: Unknown operation '%s'\n", argv[1]);
121 n = write(sockfd,buffer,strlen(buffer));
123 error(
"ERROR writing to socket");