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

C project

  • 12-03-2002 4:24pm
    #1
    Registered Users, Registered Users 2 Posts: 383 ✭✭


    hello all

    i have a client/server SMS project to do in C. basically one computer is the server and two computers are the clients. any ideas? i have a few things im playing around with but any help would be appriciated.

    jaz?


Comments

  • Closed Accounts Posts: 7,346 ✭✭✭Rev Hellfire


    I'd write the 'server' code aqnd deploy on the server and then do the 'client' code and deploy it on the clients. Also I'd only do one client program and run the same code on the two client, rather than write two apps for each client.

    If you need any more help, dont hesitate to ask.


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    Originally posted by Rev Hellfire
    I'd write the 'server' code aqnd deploy on the server and then do the 'client' code and deploy it on the clients. Also I'd only do one client program and run the same code on the two client, rather than write two apps for each client.

    If you need any more help, dont hesitate to ask.

    roffle please put a warning on posts like that my boss is looking at me after bursting out in the middle of the office while reading this :)

    Back on topic what OS? If its windows check out winsock me thinks. Or you could be really fancy and type the following in the cmd line
    net send <pc name> "<message>"
    

    kayos


  • Registered Users, Registered Users 2 Posts: 2,660 ✭✭✭Baz_


    smartarses :p


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


    yes you guys are proper meanies ;)

    as you shoud know by now jaarius, either ask a SPECIFIC question or get smartasre replys.

    tho i enjoyed HellFires post, most entertaining


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    rotfl!

    I'm with Kayos on this one - you should have a posted a warning :)

    Mebe should be moved to Humour :)

    Al.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 383 ✭✭jaarius


    using WinNT for this. im doing the server end and i will be using winsock. when we asked about netsend we were greeted with the frowning of a lifetime. i have never used winsock before and will be doinng some on-line tutorials.

    what i would like is examples. i been looking on the web for sample code but no joy. im not looking to cut and paste this or anything but some sample code could point me in the right example.

    yes goneshootin... i should know better. damn my eyes!

    jaz?


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    http://www.google.com/search?hl=en&ie=ISO-8859-1&oe=ISO-8859-1&q=windows+c+sockets+example

    91k hits...

    check your development environment help - some of them have tonnes of examples (even Visual Studio).

    Al.


  • Closed Accounts Posts: 11 V3n37


    This is a code for a very simple socket server

    // Compile and link with wsock32.lib
    //
    // Pass the port number that the server should bind() to
    // on the command line. Any port number not already in use
    // can be specified.
    //
    // Example: Server 2000
    //

    #include <stdio.h>
    #include <winsock.h>

    // Function prototype
    void StreamServer(short nPort);

    // Helper macro for displaying errors
    #define PRINTERROR(s) \
    fprintf(stderr,"\n%: %d\n", s, WSAGetLastError())

    ////////////////////////////////////////////////////////////

    void main(int argc, char **argv)
    {
    WORD wVersionRequested = MAKEWORD(1,1);
    WSADATA wsaData;
    int nRet;
    short nPort;

    //
    // Check for port argument
    //
    if (argc != 2)
    {
    fprintf(stderr,"\nSyntax: server PortNumber\n");
    return;
    }

    nPort = atoi(argv[1]);

    //
    // Initialize WinSock and check version
    //
    nRet = WSAStartup(wVersionRequested, &wsaData);
    if (wsaData.wVersion != wVersionRequested)
    {
    fprintf(stderr,"\n Wrong version\n");
    return;
    }


    //
    // Do the stuff a stream server does
    //
    StreamServer(nPort);


    //
    // Release WinSock
    //
    WSACleanup();
    }

    ////////////////////////////////////////////////////////////

    void StreamServer(short nPort)
    {
    //
    // Create a TCP/IP stream socket to "listen" with
    //
    SOCKET listenSocket;

    listenSocket = socket(AF_INET, // Address family
    SOCK_STREAM, // Socket type
    IPPROTO_TCP); // Protocol
    if (listenSocket == INVALID_SOCKET)
    {
    PRINTERROR("socket()");
    return;
    }


    //
    // Fill in the address structure
    //
    SOCKADDR_IN saServer;

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY; // Let WinSock supply address
    saServer.sin_port = htons(nPort); // Use port from command line

    //
    // bind the name to the socket
    //
    int nRet;

    nRet = bind(listenSocket, // Socket
    (LPSOCKADDR)&saServer, // Our address
    sizeof(struct sockaddr)); // Size of address structure
    if (nRet == SOCKET_ERROR)
    {
    PRINTERROR("bind()");
    closesocket(listenSocket);
    return;
    }

    //
    // This isn't normally done or required, but in this
    // example we're printing out where the server is waiting
    // so that you can connect the example client.
    //
    int nLen;
    nLen = sizeof(SOCKADDR);
    char szBuf[256];

    nRet = gethostname(szBuf, sizeof(szBuf));
    if (nRet == SOCKET_ERROR)
    {
    PRINTERROR("gethostname()");
    closesocket(listenSocket);
    return;
    }

    //
    // Show the server name and port number
    //
    printf("\nServer named %s waiting on port %d\n",
    szBuf, nPort);

    //
    // Set the socket to listen
    //

    printf("\nlisten()");
    nRet = listen(listenSocket, // Bound socket
    SOMAXCONN); // Number of connection request queue
    if (nRet == SOCKET_ERROR)
    {
    PRINTERROR("listen()");
    closesocket(listenSocket);
    return;
    }

    //
    // Wait for an incoming request
    //
    SOCKET remoteSocket;

    printf("\nBlocking at accept()");
    remoteSocket = accept(listenSocket, // Listening socket
    NULL, // Optional client address
    NULL);
    if (remoteSocket == INVALID_SOCKET)
    {
    PRINTERROR("accept()");
    closesocket(listenSocket);
    return;
    }

    //
    // We're connected to a client
    // New socket descriptor returned already
    // has clients address

    //
    // Receive data from the client
    //
    memset(szBuf, 0, sizeof(szBuf));
    nRet = recv(remoteSocket, // Connected client
    szBuf, // Receive buffer
    sizeof(szBuf), // Lenght of buffer
    0); // Flags
    if (nRet == INVALID_SOCKET)
    {
    PRINTERROR("recv()");
    closesocket(listenSocket);
    closesocket(remoteSocket);
    return;
    }

    //
    // Display received data
    //
    printf("\nData received: %s", szBuf);

    //
    // Send data back to the client
    //
    strcpy(szBuf, "From the Server");
    nRet = send(remoteSocket, // Connected socket
    szBuf, // Data buffer
    strlen(szBuf), // Lenght of data
    0); // Flags

    //
    // Close BOTH sockets before exiting
    //
    closesocket(remoteSocket);
    closesocket(listenSocket);
    return;
    }

    Sockets is not too hard to program. I would advise you to get a good book as well. The one I used was from Bob Quinn "Windows Sockets Network Programming". Quite good.

    Above code exit each time a char is received. Hopefully this will get you going.

    Taken from http://www.sockaddr.com/ExampleSourceCode.html


  • Registered Users, Registered Users 2 Posts: 383 ✭✭jaarius


    cheers V3n37

    that is well helpful. im on my way to bigger things.

    jaz?


  • Closed Accounts Posts: 536 ✭✭✭flyz


    Beej's Guide to Network programming. Tells you everything you need to know about network programming.

    http://www.ecst.csuchico.edu/~beej/guide/net/


  • Advertisement
  • Closed Accounts Posts: 11 V3n37


    Beej's guide is quite good actually, however is more unix biased, so if you're going to develop on NT you might want to look for another tutorial, although some concepts apply to Win32 as well as to UNIX.


  • Closed Accounts Posts: 536 ✭✭✭flyz


    Originally posted by V3n37
    Beej's guide is quite good actually, however is more unix biased, so if you're going to develop on NT you might want to look for another tutorial, although some concepts apply to Win32 as well as to UNIX.

    yes true, but in this case the project is being done in C.

    if it was written in C++ I wouldn't have recommended it :)


Advertisement