Question

Hi, I am stuck on a homework assignment where we use SMTP to transmit an email...

Hi,

I am stuck on a homework assignment where we use SMTP to transmit an email across a client/ server using read and send functions. I have read the unistd.h implementation of the functions read and send. Could someone possibly explain via pseudo or example how i could use this in terms of sockets? I will be using a while loop to read byte by byte the message. Not looking for a fully written program or anything , but if it helps understanding the function of sockets in an email transaction then by all means share the knowledge! ( The main function is written so just in terms of the parameters found in unix documentation.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Instad of read byte by byte you can go for structure. it will work properly according to your expectation .

so create common structure for both side and use it . I am posting sample program here. go threw it. I hope it may helpful to you.

/*server.c*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/time.h>

#include <sys/socket.h>

#include <sys/select.h>

#include <netinet/in.h>

#include <netinet/ip.h>

#include <pthread.h>

#include <unistd.h>

#include <stdio_ext.h>

#define SIZE 30

#define NAME_SIZE 15

int sock_fd,ret;

typedef struct cli_data {

char name[NAME_SIZE];

char data[SIZE];

}cli_data_t;   

int main(int argc,char **argv)

{

struct sockaddr_in connectAddr;

socklen_t len;

cli_data_t r_info;  

if(argc != 3) {

printf("Usage:./client port_number name\n");

goto done;

}

sock_fd = socket(AF_INET,SOCK_STREAM,0);

if (sock_fd == -1) {

perror("socket");

goto done;

}

printf("Client_fd: %d\n",sock_fd);

connectAddr.sin_family = AF_INET;

connectAddr.sin_port = htons(atoi(argv[1]));

connectAddr.sin_addr.s_addr = INADDR_ANY;

len = sizeof(connectAddr);

if (connect(sock_fd,(struct sockaddr *)&connectAddr,len) == -1) {

perror("connect_fail");

goto done;

}

perror("connect");

while(1) {

bzero(r_info.data,SIZE);

bzero(r_info.name,NAME_SIZE);

strcpy(r_info.name, argv[2]);

printf("Waiting for your input...............\n");

scanf(" %[^\n]",r_info.data);

if (write(sock_fd,&r_info,sizeof(cli_data_t)) == -1) {

perror("Write_Faild");

goto done;

}

if (read(sock_fd,&r_info,sizeof(cli_data_t)) == -1) {

perror("read");

goto done;

}

printf("\t\t\t\t\t\t\t\t\t\t\t%s: %s\n",r_info.name,r_info.data);   

}

done:

return 0;

}

/*client.c*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <sys/time.h>

#include <sys/socket.h>

#include <sys/select.h>

#include <netinet/in.h>

#include <netinet/ip.h>

#include <pthread.h>

#include <unistd.h>

#include <stdio_ext.h>

#define SIZE 30

#define NAME_SIZE 15

int sock_fd,ret;

typedef struct cli_data {

char name[NAME_SIZE];

char data[SIZE];

}cli_data_t;   

int main(int argc,char **argv)

{

struct sockaddr_in connectAddr;

socklen_t len;

cli_data_t r_info;  

if(argc != 3) {

printf("Usage:./client port_number name\n");

goto done;

}

sock_fd = socket(AF_INET,SOCK_STREAM,0);

if (sock_fd == -1) {

perror("socket");

goto done;

}

printf("Client_fd: %d\n",sock_fd);

connectAddr.sin_family = AF_INET;

connectAddr.sin_port = htons(atoi(argv[1]));

connectAddr.sin_addr.s_addr = INADDR_ANY;

len = sizeof(connectAddr);

if (connect(sock_fd,(struct sockaddr *)&connectAddr,len) == -1) {

perror("connect_fail");

goto done;

}

perror("connect");

while(1) {

bzero(r_info.data,SIZE);

bzero(r_info.name,NAME_SIZE);

strcpy(r_info.name, argv[2]);

printf("Waiting for your input...............\n");

scanf(" %[^\n]",r_info.data);

if (write(sock_fd,&r_info,sizeof(cli_data_t)) == -1) {

perror("Write_Faild");

goto done;

}

if (read(sock_fd,&r_info,sizeof(cli_data_t)) == -1) {

perror("read");

goto done;

}

printf("\t\t\t\t\t\t\t\t\t\t\t%s: %s\n",r_info.name,r_info.data);   

}

done:

return 0;

}

/////////////////////////////////////////////////////////////////////////

give ./server portNO form server side to run server code .

give ./client portNO YourName form client side to run client code.

It will convert your data into upper or lower case .

Add a comment
Know the answer?
Add Answer to:
Hi, I am stuck on a homework assignment where we use SMTP to transmit an email...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

  • HI, I am having trouble finsihing this program i was wondering if someone could help me....

    HI, I am having trouble finsihing this program i was wondering if someone could help me. Thanks in adavnce. Here is the code that I have so far..... //Stack.h // implementation file for the stack class #include <iostream> using namespace std; const int stack_size = 100; class stack { private: char data [stack_size]; // elements in the stack int top; // index of the top element of the stack public: stack (); // constructor creates an empty stack void push...

  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT