Thread: ntwk programming execution problem

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    22

    ntwk programming execution problem

    Hi to all,

    To the forum admin: i'm having problems with my previous account "vishamr2000". I can't post msg with it. It says "not enough privilege...". Can you fix it? Itried to reach u via email but was unsuccessful. The message got truncated each time. Thx in advance..


    Now i'm trying myself at network programming and I encountered the following problems:

    1) When you have a main program that requires arguments, how do I execute it? For example:

    Code:
    int main (int argc, char *argv[])
    {
    ...
    
    if (argc != 3) {
    	fprintf(stderr,"usage: tcpcli <IPaddress> <file pathname>");
    	exit(1);
    }
    ...
    }
    I compiled the program file like this:
    Code:
    gcc myClient.c -o myClient
    I ran it like this:
    Code:
    myClient 192.168.10.20 love.txt
    I got the following error:
    Code:
    bash: myClient: command not found
    and in this way as well:
    Code:
    ./myClient 192.168.10.20 love.txt
    I got the following error:
    Code:
    Segmentation fault

    2)In Beej's guide to Network Programming, when we have to loop several times in order receive several packets and read them, he talked about circular

    buffers. How do we implement that?

    Code:
    if ((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
    	perror("recv");
    	exit(1);
    }
    buf[numbytes] = ’\0’;
    printf("Received: %s",buf);
    This is the part that is to be looped..How can I do it?


    Any help, pointers will be most appreciated...

    Warm regards,
    Visham
    Last edited by visham; 01-23-2007 at 05:39 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    1) You've made at least two typos (the command you typed couldn't have started with gcc, and the name of the command that bash couldn't find would have to be the same as the one you typed, so if you used "myClient" it wouldn't have said "myClient1 not found") but I'm guessing that the problem is that your current directory is not in your path. Try typing "./myClient 192.168.10.20 love.txt" instead of "myClient 192.168.10.20 love.txt" (assuming the name of your executable is myClient).

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Dear Robatino,

    you're right..i made in a few mistakes in the post...i have edited the post to correct them. I had tried the way u told me but the same error appeared.
    How do I correct it if, as you say, there were a path problem?

    Warm regards,
    Visham

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    The gcc command should put the executable in the current directory. Are you trying to run it from the same shell, or a different one which may be in a different directory? If all else fails, try finding the exact full path of the executable and type out the whole path - for example if the full path is /home/visham/myClient, try
    Code:
    /home/visham/myClient 192.168.10.20 love.txt

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi again,

    To robatino: many thx for your replies...much appreciated

    There was a problem in the C program itself that caused the "./myClient 192.168.10.20 love.txt" to not work...I've corrected the program and now it's working.

    However, I don't know how to go about the second problem..Does anyone have program that contains this continuous receiving of packets?

    Warm regards,
    Visham

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM