2017-02-02 19:10:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
#include "libp2p/net/multistream.h"
|
|
|
|
|
|
|
|
int test_multistream_connect() {
|
|
|
|
int retVal = 0, socket_fd = -1;
|
|
|
|
char* response;
|
|
|
|
size_t response_size;
|
|
|
|
|
2017-02-02 23:27:57 +00:00
|
|
|
socket_fd = libp2p_net_multistream_connect("www.jmjatlanta.com", 4001);
|
|
|
|
if (socket_fd < 0)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
retVal = 1;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
|
|
|
return retVal > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_multistream_get_list() {
|
|
|
|
int retVal = 0, socket_fd = -1;
|
|
|
|
char* response;
|
|
|
|
size_t response_size;
|
|
|
|
|
2017-02-02 19:10:12 +00:00
|
|
|
socket_fd = libp2p_net_multistream_connect("www.jmjatlanta.com", 4001);
|
|
|
|
if (socket_fd < 0)
|
|
|
|
goto exit;
|
|
|
|
|
2017-02-02 20:43:35 +00:00
|
|
|
// try to respond something, ls command
|
|
|
|
const unsigned char* out = "ls\n";
|
2017-02-02 19:10:12 +00:00
|
|
|
|
|
|
|
if (libp2p_net_multistream_send(socket_fd, out, strlen((char*)out)) <= 0)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
// retrieve response
|
|
|
|
retVal = libp2p_net_multistream_receive(socket_fd, &response, &response_size);
|
|
|
|
if (retVal <= 0)
|
|
|
|
goto exit;
|
|
|
|
|
2017-02-02 23:27:57 +00:00
|
|
|
fprintf(stdout, "Response from multistream ls: %s", response);
|
|
|
|
|
2017-02-02 19:10:12 +00:00
|
|
|
retVal = 1;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
|
|
|
return retVal > 0;
|
|
|
|
}
|