Server receives some string from the client and sends the same string as response with
Code:
bytes_no = recvfrom(sock_fd, buf, 100, 0, (struct sockaddr*)&client_addr, &addr_len );
buf[bytes_no] = '\0';
printf("\nReceived '%s' with %d bytes.", buf, bytes_no);
bytes_no = sendto(sock_fd, buf, strlen(buf) + 1, 0, (struct sockaddr*)&client_addr, sizeof(struct sockaddr));
printf("\n%d sent", bytes_no);
while client sends some string and receives the response with
Code:
printf("\nRequest: ");
scanf("%s", message);
sendto(sock_fd, message, strlen(message) + 1, 0, (struct sockaddr*)&sock_addr, sizeof(struct sockaddr));
memset(message, 0, 100);
bytes_no = recvfrom(sock_fd, message, 100, 0, (struct sockaddr*)&sock_addr, &addr_len);
printf("Received '%s' with %d bytes.", message, bytes_no);
Problem comes when server with sendto() sends a response to the client. If socket is created as Internet socket, then everything works fine: server sends the response, client receives it and prints out. But, if the socket is created as Unis socket, then server does not send the response with sendto(); instead sendto() returns status -1. Why? (The code for both Unix and Internet sockets is same except in the part where different socket types are created.)
Regards!