Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

client/server socket programming

  • 29-01-2002 1:32pm
    #1
    Closed Accounts Posts: 8,478 ✭✭✭


    "Create a server, which will sent a selected file to a connected client.
    The server must have access to three different files and the client will
    Indicate whether it wants to download a specific file, 2 specific files or all three.
    The downloaded file should be displayed on the client’s terminal until the user has read them."

    so i kinda remember some programming from my waterford IT says but i need some kinda refreasher :)

    any decent links/resources out there ?


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    http://httpd.apache.org/

    Sorry, couldn't resist it. I'm weak. Sure who'd know anyway? :)

    adam


  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    c sockets are the way to go and very easy too
    quick google should give all the info u need

    http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html

    [me scans memory back to 2nd year in college]


  • Closed Accounts Posts: 5,563 ✭✭✭Typedef


    #include <stdio.h>
    #include <Stdlib.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <net/inet.h>

    #define error(x) printf("Looser Error %s\n",x); exit(0);

    int parse_command(int sock,char*command);

    int main(int argc,char**argv)
    {
    struct sockaddr_in sin;
    struct sockaddr_in linux;
    int skfd,skfd2,a;

    char command_buf[4096];
    char hello[]="Hello there you have connected to the fileserver\nThree Files are the maximum you can attempt to get\nPlease enter the filenames(onlY) incrementally";

    sin.sin_addr.s_addr=INADDR_ANY;
    sin.sin_family=AF_INET;
    sin.sin_port=htons(6666);
    skfd=socket(AF_INET,SOCK_STREAM,0);

    bind(skfd,(struct sockaddr*)&sin,sizeof(sin));
    listen(skfd,5);
    a=sizeof(linux);

    skfd2=accept(skfd,(struct sockaddr*)&linux,&a);
    printf("Accepted a connection\n");l

    send(skfd2,hello,sizeof(hello),0);
    while(1)
    {
    recv(skfd2,command_buf,sizeof(command_buf),0);
    if(parse_command(skfd2,command_buf)==-1)
    break;
    };

    close(skfd);
    close(skfd2);
    return 0;
    };

    int parse_command(int sock,char*command)
    {
    FILE*lex;
    static int attempts=0;
    char stream[1];

    if(attempts>=3)
    {printf("All attempts are over\n");
    return -1;};

    lex=fopen(command,"r");
    if(lex==NULL)
    {printf("File does not exist sorry\n");
    return 0;};

    attempts++;
    while(1)
    {
    fread(stream,1,1,lex);
    send(sock,stream,sizeof(stream),0);
    if(feof(lex)!=0)
    break;
    };
    fclose(lex);
    return 0;
    };

    Something like this?


  • Registered Users, Registered Users 2 Posts: 3,281 ✭✭✭regi




  • Registered Users, Registered Users 2 Posts: 897 ✭✭✭Greenbean


    Definitely Beej's guide - tis all you need.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,265 ✭✭✭MiCr0


    any one who did comp sci in ucd knows beej's page :)


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    If you're going to run it off Windows you may want to take a look at the Winsock API.


  • Closed Accounts Posts: 8,478 ✭✭✭GoneShootin


    no just thru unix

    TypeDef, thats WAY too complicated for my little brain, ill check back to it in 2 years when im doin my degree :)

    thanks anyway lads


Advertisement