Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdlib.h>
- int conectar_cliente(const char* ip, const char* port) {
- struct addrinfo* socketinfo;
- getaddrinfo(ip, port, NULL, socketinfo);
- // Asumo que la primera conexion es valida
- int skt = Socket(socketinfo->ai_family, socketinfo->ai_socktype, socketinfo->ai_protocol);
- // Asumo que se conecta bien
- connect(skt, socketinfo->ai_addr, socketinfo->ai_addrlen);
- freeaddrinfo(socketinfo);
- return skt;
- }
- char* buffer_aleatorio(size_t tam) {
- char* p = (char*)malloc(sizeof(char) * (tam + 1));
- if (!p) return NULL;
- p[tam] = '\0';
- srand(time(NULL)); // should only be called once
- for (size_t i = 0; i < tam; ++i) {
- p[i] = rand() % 128;
- }
- return p;
- }
- int main(int argc, char* argv[]) {
- int skt = conectar_cliente(argv[1], argv[2]);
- for (size_t i = 0; i < 50; i++) {
- char* buf = buffer_aleatorio(10);
- int enviados = 0;
- while (enviados < 10) {
- // Supongo que no hay errores ni se cierra la conexión del otro lado
- enviador += send(skt, buf, 10, NULL);
- }
- free(buf);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement