Subversion Repositories Kolibri OS

Rev

Rev 8536 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8315 superturbo 1
#include 
2
#include 
3
#include 
4
#include 
5
 
6
const char msg1[]="Hello!";
7
char msg2='\0';
8
 
9
int main()
10
{
8521 superturbo 11
    struct sockaddr addr={AF_INET4, PORT(23) , 0, 0};
8315 superturbo 12
 
13
    int sk1=socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
8540 superturbo 14
    printf("Open socket: %d. Status: %s\n",sk1, strerror(errno));
8315 superturbo 15
 
16
    bind(sk1, &addr,sizeof(addr));
8540 superturbo 17
    printf("Socket binding. Status: %s\n", strerror(errno));
8315 superturbo 18
 
19
    listen(sk1, 1);
8540 superturbo 20
    printf("Listening to a socket. Status: %s\n", strerror(errno));
21
    printf("You can connect to 'tcp server' via 'telnet' on localhost:23 !");
22
 
8315 superturbo 23
    int sk2 = accept(sk1, &addr, sizeof(addr));
8540 superturbo 24
    printf("Accept done. Status: %s\n", strerror(errno));
8315 superturbo 25
 
26
    send(sk2, msg1, strlen(msg1),MSG_NOFLAG);
8540 superturbo 27
    printf("Send message: '%s'. Status: %s\n",msg1, strerror(errno));
8315 superturbo 28
    puts("Received data:");
29
    while(msg2!='!')
30
    {
31
        recv(sk2, &msg2, 1, MSG_NOFLAG);
32
        printf("%c",msg2);
33
    }
34
    close(sk1);
35
    close(sk2);
36
    puts("\nGood bye!");
37
    exit(0);
38
}