fafa70 0 Newbie Poster

hi.
i create a server and client and i have a text based connection between them.
firstly client sends a message to server and client gets the answer but after that client sends another message to server and when client wants to get the message, it shows empty message.
important part of client and server code is as below:

//client code
write(2,"print file name : ",18);   
                nread2=read(0,FileName,8);

                write(2,FileName,nread2);
                if(send(sock , FileName , 8 , 0) < 0){perror("error happened");}
                //puts("\ndata has been sent.");
                if((SizeOfText=recv(sock,buffer2,1000,O_NONBLOCK)) < 0)
                {
                    write(2,"\nerror\n",7);
                    break;
                }
                write(2,buffer2,SizeOfText);
                int filedesc = open(FileName, O_WRONLY | O_CREAT | O_TRUNC , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
                if (filedesc < 0)
                {
                        return -1;
                    }
                    if (write(filedesc, buffer2, SizeOfText) != SizeOfText) 
                {
                        write(2, buffer2, SizeOfText);
                        return -1;
                }
//server code
if ((fd=open(client_message, O_RDONLY)) < 0)
        {
            perror("unable to open.");
            exit(1);
        }
        int size = read(fd, buf, 10000);
        write(2,buf,size);      
        if(send(socket_desc,buf,size,0) < 0){perror("error");}