[Oz] Help Needed

Valentin Mesaros valentin at info.ucl.ac.be
Fri Sep 24 09:56:21 CEST 1999


Dear Ravi,

I've tried your Oz server with a java client.
It seems that the problem you've encountered is comming from the way you
called the read method of the Open.socket class.
By using the atom 'all' , it will try to read the whole input of the TCP
buffer of a certain socket. Thus, everything is OK when you call the
server with clients which writes only a small amount of data. But when a
certain client tries to write large amount of data or some data within a
large loop, most probably the system will return a memory alocation
error.
My suggestion is to use the methods available in Open.text class in
order to read the incoming data in a buffered way.       

Sincerely
Valentin

> Date: Fri, 17 Sep 1999 08:28:29 +0200
> From: ravi at konark.ncst.ernet.in
> 
> Hi,
> 
> I am getting a problem with an Oz server. The task is as follows: The
> server should take in Oz functors, evaluate, execute, and return the
> result to the client. The communication is using sockets.
> 
> I have written the program.  It generally seems to work fine. But, when
> the requests are sent continuously (invoking the client in an infinite
> loop in a shell script), it is misbehaving: On linux Red hat 5.2 it hangs,
> and on Solaris 2.5 it gives "Segmentation Fault." Could some one point
> me out what is the problem with the code (given below)? I am using Mozart.
> 
> Regards,
> 
> Ravi
> 
> -----------------------------------------------------------------------------
> %Server Code
> 
> functor
>   import
>     Module
>     Compiler
>     Open
>     Application
>     System
> 
> define
> 
> class Accepted from Open.socket
> 
>      meth reportWrap(H P)
>        FinalString Pr M Result
>      in
>        try
>          {self read(list: FinalString size: all)}
> 
>          Pr = {Compiler.virtualStringToValue FinalString}
>          [M]={Module.apply [Pr]}
>          Result = {M.jj}
> 
>          {System.printError Result}
>          {self send(vs:Result)}
>          {self flush}
>          {self shutDown(how: [receive send])}
>          {self close}
>        catch X then
>            {System.show [exception X]}
>        end
>      end
> end
> 
> proc {Accept}
>    SP S
>    proc{AcceptAux S RNo}
>      CH CP A
>    in
>      {S accept(acceptClass:Accepted host:?CH port:?CP accepted:?A)}
>      {System.showInfo "Request No: "#RNo}
>      thread
>        {A reportWrap(CH CP)}
>      end
>      {AcceptAux S (RNo + 1)}
>    end
>  in
>    S={New Open.socket init}
>    SP={S bind(takePort:7777 port:$)}
>    {System.show SP}
>    {S listen(backLog:5)}
>    {AcceptAux S 1}
> end
> 
>   {Accept}
>   {Application.exit 0}
> 
> end
> 
> ------------------------------------------------------------------------------
> 
> %Client Code
> 
> /*
> Which sends the oz code to the server and gets the results from the server
> using sockets.
> */
> 
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <arpa/inet.h>
> 
> 
> void *work();
> int j;
> int count = 0;
> 
> int main(int argc, char ** argv)
> {
>    int i;
> 
>    for(j = 0; j < 1; j++){
>      work();
>      }
> 
>   exit(0);
> }
> 
> void *work()
> {
>   char instr[1000];
>   char outstr[] = "functor $ import System export jj: JJ define fun{JJ} L in {Li
> st.mapInd {List.make 100} fun{$ Ind E} Ind end L} {FoldL L fun{$ E Z} E + Z end
> 0} end end";
> 
>   int sockfd;
>   struct sockaddr_in servaddr;
>   int cnt = 0;
>   char ch;
> 
>   if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
>     perror("socket"), exit(-1);
>   bzero(&servaddr, sizeof(servaddr));
>   servaddr.sin_family = AF_INET;
>   servaddr.sin_port = htons(7777);
>   inet_pton(AF_INET, "144.16.2.1", &servaddr.sin_addr);
>   if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == -1)
>     perror("connect"), exit(-1);
> 
>   write(sockfd, outstr, strlen(outstr));
> 
> 
> 
>   if(shutdown(sockfd,1) == -1)
>     perror("shutdown1"), exit(-1);
> 
>   while(read(sockfd, &ch, 1) != 0)
>     instr[cnt++] = ch;
>   instr[cnt] = '\0';
> 
>   printf("Reply from the server for: %s\n", instr);
> 
>   if(close(sockfd) == -1)
>     perror("close"), exit(-1);
> }
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.





More information about the mozart-users mailing list