Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<sys/types.h>
- #include<sys/socket.h>
- #include <stdio.h>
- #include <netinet/in.h>
- #include <netinet/ip.h>
- #include <string.h>
- int main(){
- int c;
- struct sockaddr_in server;
- char string[100], oglindit[100];
- c = socket(AF_INET, SOCK_STREAM, 0);
- if (c < 0) {
- printf("Eroare la crearea socketului client\n");
- return 1;
- }
- memset(&server, 0, sizeof(server));
- server.sin_port = htons(1274);
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = inet_addr("127.0.0.1");
- if (connect(c, (struct sockaddr *) &server, sizeof(server)) < 0) {
- printf("Eroare la conectarea la server\n");
- return 1;
- }
- printf("Dati sirul de caractere: ");
- fgets(&string, 100, stdin);
- uint16_t length = strlen(string);
- length = htons(length);
- send(c, &length, sizeof(length), 0);
- send(c, &string, strlen(string)*sizeof(char), 0);
- recv(c, oglindit, strlen(string), MSG_WAITALL);
- printf("%s\n", oglindit);
- close(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement