Google Answers Logo
View Question
 
Q: Operating Systems ( No Answer,   2 Comments )
Question  
Subject: Operating Systems
Category: Computers > Operating Systems
Asked by: axmedeey-ga
List Price: $30.00
Posted: 28 Apr 2004 02:16 PDT
Expires: 18 May 2004 09:55 PDT
Question ID: 337496
QUESTION 1)
This part is concerned with network programming in C based upon the
UNIX sockets interface.
----------------
/* sender.c */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>

#define DATA "My first datagram . . ."

/* usage: sender hostname portnumber */
main(argc, argv)
int argc;
char *argv[];
{
     int sock;
     struct sockaddr_in name;
     struct hostent *hp, *gethostbyname();

     /* Create socket on which to send. */
     sock = socket(AF_INET,SOCK_DGRAM, 0);
     if (sock == -1) {
          perror("opening datagram socket");
          exit(1);
     }

     /* Construct name, with no wildcards, of the socket to ``send'' to. */
     hp = gethostbyname(argv[1]);
     if (hp == (struct hostent *) 0) {
          fprintf(stderr, "%s: unknown host\n", argv[1]);
          exit(2);
     }
     memcpy((char *) &name.sin_addr, (char *) hp->h_addr, hp->h_length);
     name.sin_family = AF_INET;
     name.sin_port = htons( atoi( argv[2] ));

     /* Send message. */
     if (sendto(sock,DATA, sizeof DATA ,0,(struct sockaddr *)
&name,sizeof name) == -1)
          perror("sending datagram message");

     close(sock);
     exit(0);
}
----------------
/* receiver.c */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>

main()
{
     int sock, length;
     struct sockaddr_in name;
     char buf[1024];

     /* Create socket from which to read. */
     sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock == -1) {
          perror("opening datagram socket");
          exit(1);
     }

     /* Create name with wildcards. */
     name.sin_family = AF_INET;
     name.sin_addr.s_addr = INADDR_ANY;
     name.sin_port = 0;
     if (bind(sock,(struct sockaddr *)&name, sizeof name) == -1) {
          perror("binding datagram socket");
          exit(1);
     }

     /* Find assigned port value and print it out. */
     length = sizeof(name);
     if (getsockname(sock,(struct sockaddr *) &name, &length) == -1) {
          perror("getting socket name");
          exit(1);
     }
     printf("Socket port #%d\n", ntohs( name.sin_port));

     /* Read from the socket. */
     if ( read(sock, buf, 1024) == -1 )
          perror("receiving datagram packet");
     printf("-->%s\n", buf);

     close(sock);
     exit(0);
}
----------------

A) Do the above programs create Unix domain sockets? 

B) What protocol do you think is being used for communication of the
message between sender and receiver?

C) How has this protocol been specified please? 

D) Does a connection get established between sender and receiver? 

E) Does the program variable name point to information about a local socket 
in the program sender.c?  

F) in the program receiver.c? 

G) What small change do you think should be made to each program if
one decided to reserve port 3000 for communication of the message?

H) What small change should be made to receiver.c if one wanted it to
continue to read and print messages, rather than to terminate after a
single message?

I) With what system call should read() be replaced, if functionality
is to be added to receiver.c that requires the return-address of the
message?


QUESTION 2)

This part is also concerned with network programming, but i would like
you to write all your programs in Java.
A new service enables users to exchange 5 lines of text per session.
Two users at a time may access the service anonymously. Each writes a
line and, when both lines have been written, they are exchanged. Then
the users each write a second line, and so on. While this is going on,
other users will be unable to begin a session.

A) can you please write a server program for me that provides this
service at port 2347 on some machine.

B) can you write a client program for me that can be used to access the service. 

C) can you provide a sample of output from two clients involved in the
same session.

D) can you write a proxy program (capable of handling at most one
client at a time) that relays lines of text between client and server.

E) can you rewrite the server program using multithreading so that it
can handle up to three simultaneous sessions.

F) can you rewrite the proxy program using multithreading so that it
is also capable of handling multiple clients at the same time.

thank you for your helping.
by

Clarification of Question by axmedeey-ga on 13 May 2004 13:09 PDT
This Question is concerned with network programming, but i would like
you to write all your programs in Java.
A new service enables users to exchange 5 lines of text per session.
Two users at a time may access the service anonymously. Each writes a
line and, when both lines have been written, they are exchanged. Then
the users each write a second line, and so on. While this is going on,
other users will be unable to begin a session.

A) can you please write a server program for me that provides this
service at port 2347 on some machine.

B) can you write a client program for me that can be used to access the service. 

C) can you provide a sample of output from two clients involved in the
same session.

D) can you write a proxy program (capable of handling at most one
client at a time) that relays lines of text between client and server.

E) can you rewrite the server program using multithreading so that it
can handle up to three simultaneous sessions.

F) can you rewrite the proxy program using multithreading so that it
is also capable of handling multiple clients at the same time.

thank you for your helping.
by
Answer  
There is no answer at this time.

Comments  
Subject: Re: Operating Systems
From: yhal-ga on 03 May 2004 06:30 PDT
 
1)
A: no
B: UDP
C: sock = socket(AF_INET, SOCK_DGRAM, 0);
D: see B
...

argh... You'd better make your homework by yourself.
Subject: Re: Operating Systems
From: axmedeey-ga on 04 May 2004 10:43 PDT
 
this is not a homework it is my awn reseach, so please if you can help
it will be very kind of you thank you  very much by.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy