#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/time.h>
int
sockNodeCnn;
int
ConnectServer()
{
int
iRet = 0;
struct
sockaddr_in
sin
;
if
(sockNodeCnn > 0)
{
printf
(
"\n>>>>%d<<<<\n"
,__LINE__);
return
1;
}
bzero(&
sin
,
sizeof
(
sin
));
sin
.sin_family = AF_INET;
sin
.sin_port = htons(7);
sin
.sin_addr.s_addr = inet_addr(
"192.168.1.103"
);
bzero(&
sin
.sin_zero, 8);
sockNodeCnn = socket(AF_INET, SOCK_STREAM, 0);
if
(sockNodeCnn < 0)
{
printf
(
"\n>>>>%d<<<<\n"
,__LINE__);
return
0;
}
iRet = connect(sockNodeCnn, (
struct
sockaddr *)&
sin
,
sizeof
(
sin
));
if
(iRet < 0)
{
return
0;
}
printf
(
"\n>>>>%d<<<<\n"
,sockNodeCnn);
}
int
CloseServer(
int
i)
{
if
(shutdown(sockNodeCnn,SHUT_RDWR))
{
}
else
{
sockNodeCnn = 0;
}
}
int
SendMsg(
const
uint8_t *strCmd,
int
nLength)
{
int
iSockfd = sockNodeCnn;
int
nWrite;
struct
timeval tmvTimeOut;
tmvTimeOut.tv_sec = 1;
tmvTimeOut.tv_usec = 0;
if
(nLength == 0)
{
return
1;
}
if
(iSockfd <= 0)
{
return
0;
}
nWrite = write(iSockfd, strCmd, nLength);
if
(nWrite < 0)
{
return
0;
}
return
1;
}
int
main()
{
int
i;
uint8_t str[10000],dest[10000];
memset
(str,1,10000);
memset
(dest,0,10000);
int
iRet = ConnectServer();
struct
timeval start;
struct
timeval end;
gettimeofday(&start,NULL);
SendMsg(str,10000);
read(sockNodeCnn,dest,10000);
gettimeofday(&end,NULL);
long
diff = 1000000 * (end.tv_sec-start.tv_sec)+ end.tv_usec-start.tv_usec;
printf
(
"thedifference is %ld\n"
,diff);
for
(i=0; i<100; i++)
{
printf
(
"%d"
,dest[i]);
}
}