is there any problem with functions and sockets?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers is there any problem with functions and sockets?
# 1  
Old 12-29-2010
is there any problem with functions and sockets?

hi
I am writing a client-server program and the functions I've written on the server are never executed. even something as easy as typing hello does not. is there something to be taken into account to use functions?
I appreciate any information
# 2  
Old 12-29-2010
Without more information it is hard to give any sort of a useful answer. Can you show us your code?
# 3  
Old 12-30-2010
This is the code of my program

Code:
void getFiles(int siz, char *root, char *infor)
{
DIR *d;
  struct dirent *ent;
  struct stat inode;
  
  
  if ((d = opendir (root)) != NULL)
  {
    chdir (root);

    while(ent=readdir(d))
    {

     
     lstat (ent->d_name, &inode);


      if (S_ISDIR(inode.st_mode) && strcmp(ent->d_name, ".") && strcmp(ent->d_name, ".."))
      {
        
        getFiles(siz, ent->d_name, infor);
        chdir("..");
        
      } //if
    } //while

  } //if
}

int main() 
{
    char root[256];
    char buffer[125];
    
    struct sockaddr_in cli, serv;
    int sfd; 
    char result[1024];
    char infor[1024];
    char size[10];
    int siz;
    int siz_cli = sizeof(cli);
    int siz_serv = sizeof(serv);
    //////////////////////////////////////////////
    serv.sin_family = AF_INET;
    
    serv.sin_port = 5556;
    serv.sin_addr.s_addr = inet_addr("127.0.0.1"); 
    /////////////////////////////////////////////
    sfd = socket(AF_INET, SOCK_DGRAM, 0); 
    
    int vbleBind = bind(sfd, (struct sockaddr*) &serv, siz_serv);
    if(vbleBind == -1)
    {
        perror("error \n");
        return 0;
    }
    else
    {
     while( 1 )
     {
        
        if( (recvfrom(sfd, size, 10, 0,(struct sockaddr *) &cli, &siz_cli) ) < 0)
        
        {
            perror("error \n");
            return 0;
        }
        else
        {
        
        siz=atoi(size);
        
        system("pwd>root");
        int fd=open("root", O_RDWR, 644);

        while( read(fd, buffer, 4) > 0 )
        {
        strcat(root,buffer);
        }
        
        
        getFiles(siz, root, infor);
        
         sendto(sfd, result, 1024, 0, (struct sockaddr *) &cli, siz_cli);
         close(fd);
         }
    }//while
    
    close(sfd);
  }//else
}

Thanks

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by fpmurphy; 12-30-2010 at 10:25 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Any example about sockets in C++?

Hi, i am student, think learning about c++, someone has a example the how establish a conection with sockets :b::b: (1 Reply)
Discussion started by: mmartinez
1 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Programming

help: problem with sockets write/read

I am trying to make a server and client, the client will choose between some options and the server will react accordingly. After a some reads and writes that work the server needs to read from client an INT i use this: read(newSd,&k,sizeof(int));But even if all the other times there was no... (1 Reply)
Discussion started by: theSling
1 Replies

4. Programming

Sockets

Hi,i now moved into a different section where i need to use sockets. i am completely nill in sockets. can some body please provide me what are the requirements for a socket. to use sockets in c. thanks (1 Reply)
Discussion started by: MrUser
1 Replies

5. Programming

problem with lots of open sockets

I'm programming in C with lots of sockets, (asynchronous handling), and for a while it goes ok, but after a while it starts to hang, or not get complete connections anymore. checking my router, i see that i get nat tables overflow and even my DNS cacher seems to be having serious issues... ... (4 Replies)
Discussion started by: alien999999999
4 Replies

6. Programming

Problem in file transfer using sockets

Hai Friends I am writing a c program to transfer files from one system to another using TCP/IP socket programming.. My Recieve Program #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> extern int errno; extern char *sys_erlist; void... (2 Replies)
Discussion started by: collins
2 Replies

7. Programming

need help with sockets

anyone and teach me how to save standard output to a file in a client/server socket. I know how to read them to the screen but i'm not quite sure how to save them to a file. my read to screen file code: memset(line, 0x0, LINE_ARRAY_SIZE); while (recv(connectSocket, line, MAX_MSG, 0) >... (1 Reply)
Discussion started by: crunchyuser
1 Replies

8. UNIX for Dummies Questions & Answers

sockets

how do i mointor how many sockets are opened from a particular foriegn address? (2 Replies)
Discussion started by: kirpond
2 Replies

9. Programming

sockets

Hai, How cani declare socket and collect the data in a string varialbe. Since i am new to this i am asking this. Can we connect multiple port. Thank you. (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

10. Programming

sockets...

Hi ! I had a verry simple question to ask... In unix when we create pipes.. the unnamed pipes that is... is there any way to access those pipes outside the code ? Another thing.. do sockets have an entry in the inode table ? TIA, Devyani. (1 Reply)
Discussion started by: devy8
1 Replies
Login or Register to Ask a Question