Rev 8521 | 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); |
||
8536 | superturbo | 14 | printf("Open socket: %d. Error: %d\n",sk1, errno); |
8315 | superturbo | 15 | |
16 | bind(sk1, &addr,sizeof(addr)); |
||
8536 | superturbo | 17 | printf("Socket binding. Error: %d\n", errno); |
8315 | superturbo | 18 | |
19 | listen(sk1, 1); |
||
8536 | superturbo | 20 | printf("Listening to a socket. Error: %d\n", errno); |
8315 | superturbo | 21 | int sk2 = accept(sk1, &addr, sizeof(addr)); |
8536 | superturbo | 22 | printf("Accept done. Error: %d\n", errno); |
8315 | superturbo | 23 | |
24 | send(sk2, msg1, strlen(msg1),MSG_NOFLAG); |
||
8536 | superturbo | 25 | printf("Send message: '%s' Error: %d\n", msg1, errno); |
8315 | superturbo | 26 | puts("Received data:"); |
27 | while(msg2!='!') |
||
28 | { |
||
29 | recv(sk2, &msg2, 1, MSG_NOFLAG); |
||
30 | printf("%c",msg2); |
||
31 | } |
||
32 | close(sk1); |
||
33 | close(sk2); |
||
34 | puts("\nGood bye!"); |
||
35 | exit(0); |
||
36 | } |