pedz@smu.UUCP (06/12/84)
#N:smu:18600013:000:4504 smu!pedz Jun 11 21:22:00 1984 #bug food We have 4.2 bsd on a Vax 11/780 and I have a problem with sockets. The two program below are to be used as the client and server of a socket. The server program simply opens the socket and waits for a client. When a client comes the server reads from the socket and echoes what is read to the screen. The client simply opens the socket, sends out a messages and closes it. The code in comments was to reverse the link and send data from the server back to the client which is what I want to do eventually. The getline routine is common between both programs. I have tried to copy the lpd and startdeamon code from the lpr as closely as I thought I needed to. My problem is not that the two programs do not work (although I can not find anything which is wrong with them. The bigger problem is that when the server is started and then the client is started (from another terminal) the program does not work. Typing ^C causes the client to terminate, then the server is killed. The first time this process is done all is fine. However on the second time, the machine "crashes". The crash is put into quotes because it actually does not crash with a dump and all of that good stuff, but is instead left in a unuseable state. Interrupts from the keyboard get serviced but very slowly (like 10 to 15 seconds to echo a character) and all normal processing seems to stop. Eventually the machine is stopped and rebooted from the console. (The console is also dead as far as normal i/o is concerned. Of course ^P still works which is used to halt the machine.) Has this problem been seen before and has it a fix or a work around? Second, can you spot any obvious error in the program? (A second note, all of this is done from a non-privileged state.) Also, the IPC primer has an inaccuracy in it when it says that a socket may be bound to a path simply by putting the pathname and its length as the second and third arguments to bind. Thank you for you help, Perry convex!smu!pedz ------------------------------------------------------------------ /* This is a test program for the server action of a socket pair. It will setup and open a socket, then accept request on the socket. When a request is received, the info will be copied from the socket to the screen. Then a message of "SEX IS FUN FOR ALL" will be sent back to the client, the socket closed and another request accepted. */ #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #define SOCKETNAME "/tmp/pedzsocket" struct sockaddr_un socket1, socket2; main() { int file1, file2; int len1, len2; char buf[512]; int i; printf("server1\n"); unlink(SOCKETNAME); file1 = socket(AF_UNIX, SOCK_STREAM, 0); socket1.sun_family = AF_UNIX; strcpy(socket1.sun_path, SOCKETNAME); len1 = strlen(socket1.sun_path) + 2; if (bind(file1, &socket1, len1) < 0) { perror("server1"); exit(1); } printf("server2\n"); listen(file1, 2); printf("server3\n"); for (;;) { len2 = sizeof(socket2.sun_path); if (file2 = accept(file1, &socket2, &len2) < 0) { perror("server2"); exit(1); } printf("server4\n"); getline(file2, buf); printf(buf); /* printf("server5\n"); send(file2, "SEX IS FUN FOR ALL\n", 19, 0); */ close(file2); printf("server6\n"); } } --------------------------------------------------------------------- /* This is a test program for the client action of a socket pair. It will open a socket, bind it to the server, send a message and then receive a message. */ #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #define SOCKETNAME "/tmp/pedzsocket" struct sockaddr_un socket1, socket2; main() { int file1, file2; int len1, len2; char buf[512]; int i; printf("client1\n"); file1 = socket(AF_UNIX, SOCK_STREAM, 0); if (file1 < 0) { perror("client"); exit(1); } printf("client2\n"); socket1.sun_family = AF_UNIX; strcpy(socket1.sun_path, SOCKETNAME); len1 = strlen(socket1.sun_path) + 2; if (connect(file1, &socket1, len1) < 0) { perror("client"); exit(1); } printf("client3\n"); send(file1, "LIFE IS BUT A DREAM\n", 20, 0); /* printf("client4\n"); getline(file1, buf); printf(buf); */ printf("client5\n"); close(file1); } ----------------------------------------------------------------- getline(i, buf) int i; char *buf; { char *temp; int j; printf("start getline\n"); temp = buf; do j = read(i, temp, 1); while (*temp++ != '\n'); *temp = '\0'; printf("end getline\n"); }