-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
63 lines (60 loc) · 2.06 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/********************************************************************/
/* Copyright (C) SSE-USTC, 2012 */
/* */
/* FILE NAME : client.c */
/* PRINCIPAL AUTHOR : SLK */
/* SUBSYSTEM NAME : system */
/* MODULE NAME : client */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : Linux */
/* DATE OF FIRST RELEASE : 2012/12/10 */
/* DESCRIPTION : Vampire KV system based on TC M2 */
/********************************************************************/
/*
* Revision log:
*
* Created by SLK,2012/12/10
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
#include "net.h"
#include "dbapi.h"
int main(int argc, char **argv)
{
char recvBuf[MAX_BUFFER_SIZE] = "";
char *sendBuf = (char*) malloc(MAX_BUFFER_SIZE * sizeof(char));
char addr[40];
int sockfd;
int port;
printf("Please input server's IP: ");
scanf("%s", addr);
printf("Please input server's PORT: ");
scanf("%d", &port);
sockfd = InitClient(sockfd, addr, port);
printf("Connected!\n");
if (RecvMsg(sockfd, recvBuf) == 0)
{
SendMsg(sockfd, "recved");
printf("%s", recvBuf);
}
while (1)
{
if (RecvMsg(sockfd, recvBuf) == 0)
{
//SendMsg(sockfd, "recved");
printf("%s", recvBuf);
}
if (strcmp(recvBuf, "exit success!\n") == 0)
break;
//printf("command:\n");
fgets(sendBuf, MAX_BUFFER_SIZE, stdin);
printf("%s", sendBuf);
*(sendBuf + strlen(sendBuf) - 1) = '\0';
if (SendMsg(sockfd, sendBuf) == 0)
RecvMsg(sockfd, recvBuf);
}
ShutdownSocket(sockfd);
}