Register for your free account! | Forgot your password?

You last visited: Today at 06:22

  • Please register to post and access all features, it's quick, easy and FREE!


Server

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2010
Posts: 75
Received Thanks: 5
Server

Den Server auf echo testen:
nur sehr wenige kann es weiter bringen also lass die dummen Kommentare schon erstmal weg.
Server echo:
Code:
#include <sys/socket.h> 
#include <sys/stat.h> 
#include <arpa/inet.h> 
#include <stdio.h> 
#include <string.h> 
 
int main(int argc, char **argv) 
{ 
    int server_sockfd, client_sockfd; 
    int client_len, n; 
    char buf[80]; 
    struct sockaddr_in clientaddr, serveraddr; 
 
    client_len = sizeof(clientaddr); 
 
    if ((server_sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) 
    { 
        perror("socket error : "); 
        exit(0); 
    } 
    bzero(&serveraddr, sizeof(serveraddr)); 
    serveraddr.sin_family = AF_INET; 
    serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); 
    serveraddr.sin_port = htons(atoi(argv[1])); 
 
    bind (server_sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); 
    listen(server_sockfd, 5); 
 
    while(1) 
    { 
        memset(buf, 0x00, 80); 
        client_sockfd = accept(server_sockfd, (struct sockaddr *)&clientaddr, 
                            &client_len); 
 
        if ((n = read(client_sockfd, buf, 80)) <= 0) 
        { 
            close(client_sockfd); 
            continue; 
        } 
        if (write(client_sockfd, buf, 80) <=0) 
        { 
            perror("write error : "); 
            close(client_sockfd); 
        } 
        close(client_sockfd); 
    } 
}
Client echo:
Code:
echo_client.c
#include <sys/stat.h> 
#include <arpa/inet.h> 
#include <stdio.h> 
#include <string.h> 
 
int main(int argc, char **argv) 
{ 
    struct sockaddr_in serveraddr; 
    int server_sockfd; 
    int client_len; 
    char buf[80]; 
    char rbuf[80]; 
 
 
    if ((server_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
    { 
        perror("error :"); 
        exit(0); 
    } 
 
    server_sockfd = socket(AF_INET, SOCK_STREAM, 0); 
    serveraddr.sin_family = AF_INET; 
    serveraddr.sin_addr.s_addr = inet_addr("218.234.19.87"); 
    serveraddr.sin_port = htons(atoi(argv[1])); 
 
    client_len = sizeof(serveraddr); 
 
    if (connect(server_sockfd, (struct sockaddr *)&serveraddr, client_len) < 0) 
    { 
        perror("connect error :"); 
        exit(0); 
    } 
 
    memset(buf, 0x00, 80); 
    read(0, buf, 80); 
    if (write(server_sockfd, buf, 80) <= 0) 
    { 
        perror("write error : "); 
        exit(0); 
    } 
    memset(buf, 0x00, 80); 
    if (read(server_sockfd, buf, 80) <= 0) 
    { 
        perror("read error : "); 
        exit(0); 
    } 
    close(server_sockfd); 
    printf("read : %s", buf); 
}



Eifelturm is offline  
Reply



« [HELP] Itemstealer | MySQL Downloadlink »



All times are GMT +1. The time now is 06:22.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.