#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
//#include <arpa/inet.h>
#define MSG_LEN 512
void SendCommand(char str[], int s)
{
char msg[MSG_LEN];
int res;
res = send(s, str, strlen(str), 0);
if (res <= 0)
{
close(s);
return;
}
memset(msg, 0, MSG_LEN);
res = recv(s, msg, MSG_LEN, 0);
if (res <= 0)
{
close(s);
return;
}
printf("%s\n", msg);
}
int main(void) {
int s, res;
struct sockaddr_in taddr;
char msg[MSG_LEN];
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0) {
perror("socket");
return 1;
}
memset(&taddr, 0, sizeof(struct sockaddr));
taddr.sin_family = AF_INET;
taddr.sin_port = htons(2000);
taddr.sin_addr.s_addr = inet_addr("127.0.0.1");
res = connect(s, (struct sockaddr*)&taddr, sizeof(struct sockaddr));
if (res < 0) {
close(s);
perror("connect");
return 1;
}
memset(msg, 0, MSG_LEN);
res = recv(s, msg, MSG_LEN, 0);
if (res <= 0)
{
close(s);
return -1;
}
printf("%s\n", msg);
SendCommand("nxt; open",s);
SendCommand("nxt; open",s);
close(s);
return 0;
}