Thread: Can someone do me this?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, I can't help because I don't know network programming.
    And I was asking because you seem intent on doing it in C/C++ just because you don't want to ship winsock.ocx.
    But I'm telling you that even if you do C/C++, you'll still have to redistribute dlls, possibly even install depending on what compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    May 2008
    Posts
    52
    Does every DLL need to be installed? His presence in the same folder as the .EXE is not enough?

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Runtime can be a complex thing. VB has its own runtime and so does C/C++.
    They need to exist on the target computer.
    Some runtimes can be placed in the app directory, some cannot. It depends on the compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I'm sure if you goto www.rentacoder.com, you'll find someone to do it at a price you're willing to pay.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #20
    Registered User
    Join Date
    May 2008
    Posts
    52
    I'll ask some friend of myne to do it then....

  6. #21
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    I don't know whether to laugh or cry, so I did a little of both...

    double digits shouldnt be allowed near computers, drooling on the keyboard could cause electrocution among other annoying results, like posting.

  7. #22
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    What do you mean the program will connect through telnet? Is there a telnet server or is the actual program you want written the server, and YOU connect to it through telnet?

    EDIT: Heres some code i've written for you. I have not tested it (you havnt provided the server program for me to test it with) but it compiles without any warnings/errors. You need to link the wsock32 lib

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <winsock2.h>
    #include <windows.h>
    
    
    const char SERVER_IP[] = "127.0.0.1";
    const unsigned short SERVER_PORT = 8674;
    
    size_t RecvLine(unsigned int socketId, char* out, size_t outSize);
    
    int main (int argc, char *argv[])
    {
        char msgBuffer[0xFFFF];
    
        //Initialize Winsock (version 2.2)
        WSADATA wsaData;
        WSAStartup(MAKEWORD(2, 2),&wsaData);
    
    
        //Create a TCP socket
        unsigned int socketId = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if(socketId)
        {
            //Fill in server IP and PORT into address header
            SOCKADDR_IN addr;
            addr.sin_family = AF_INET;
            addr.sin_addr.s_addr = inet_addr(SERVER_IP);
            addr.sin_port = htons(SERVER_PORT);
    
            //Try and connect to the server
            if(connect(socketId, (SOCKADDR*)&addr, sizeof(addr)) != -1)
            {
                //If we succesfully connected, than send the "AUTH 1287" message
                strncpy(msgBuffer, "AUTH 1287\n", sizeof(msgBuffer));
                send(socketId, msgBuffer, strlen(msgBuffer), 0);
    
                //Receive the next line
                if(RecvLine(socketId, msgBuffer, sizeof(msgBuffer)))
                {
                    //Check if the line we received is "Correct! 250"
                    if(strcmp(msgBuffer, "Correct! 250") == 0)
                    {
                        while(1)
                        {
                            //Send the "Show stats" line
                            strncpy(msgBuffer, "Show stats\n", sizeof(msgBuffer));
                            send(socketId, msgBuffer, strlen(msgBuffer), 0);
                            Sleep(60000); //Wait 60 secs
                        }
    
                    } else printf("Error. Incorrect response from server\n");
                }
    
    
            }
    
        }
        
        //Free winsock
        WSACleanup();
        return 1;
    }
    
    //Receives a line from a socket
    size_t RecvLine(unsigned int socketId, char* out, size_t outSize)
    {
        char byte;
        size_t recvCount = 0;
    
        //Clear the out buffer
        memset(out, 0, outSize);
    
        for(; recvCount < outSize - 1; ++recvCount)
        {
            if(recv(socketId, &byte, 1, 0) > 0)
            {
                if(byte != '\n')
                    out[recvCount] = byte;
                else break;
            } else break;
        }
    
        //Trim the line (any \r, \n,etc)
        while(recvCount)
        {
            if(out[recvCount-1] < ' ')
                out[--recvCount] = 0;
            else break;
        }
    
        return recvCount;
    }
    As you can see it's alot more complex than what you would do in VB and you should have a decent amount of c/c++ knowledge before you go into sockets.
    Last edited by 39ster; 06-01-2008 at 09:32 AM.

  8. #23
    Registered User
    Join Date
    May 2008
    Posts
    52
    Thank you very much 39ster!! It works very well! Thank you!

  9. #24
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well done, 39ster. You've just rewarded NeMewSys's laziness.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #25
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's a shame it came to that - nagging rewarded with spoon-feeding.

    At least the code is riddled with lots of subtle bugs, that's my only consolation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #26
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    uhhg... you have got to be kidding.

    Probably best to close this thread before it opens up into a war
    Last edited by zacs7; 06-01-2008 at 08:36 AM.

  12. #27
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    Or they could of closed it before if they didnt want anyone to help him.

  13. #28
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by 39ster View Post
    Or they could of closed it before if they didnt want anyone to help him.
    You dont help a wino by giving them money for booze. All you did was reinforce his behavior. Instead of learning to program, he learned that nagging will get him what he wants.

  14. #29
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    Quote Originally Posted by abachler View Post
    You dont help a wino by giving them money for booze. All you did was reinforce his behavior. Instead of learning to program, he learned that nagging will get him what he wants.
    The guy's already said he's tried for days and couldnt figure it out. All my knowledge of C comes from reading peoples source code and reading tutorials and when i was in his position, frustrated because i just cant figure it out, it would of been great for someone to write it out for me so i could learn from their code.
    I was also very bored at the time and wanted something to do.

  15. #30
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    We were tryign to hel;p him but he woudlnt provide any information on what he had already tried so we coudl show him where he went wrong. Sometimes fixig the problem means fixing why there is a problem as well. Don't just fix the broken part; fix what broke the part in the first place.

    Maybe thats why i hated factory maintenance.

Popular pages Recent additions subscribe to a feed