C++ WinSock if statement, send message back. menu

Shout-Out

User Tag List

Results 1 to 7 of 7
  1. #1
    Moskis's Avatar Member
    Reputation
    13
    Join Date
    Nov 2008
    Posts
    38
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C++ WinSock if statement, send message back.

    Hey! I got my C++ first Client/Server project almost done. It's a project that connects to the server and then if you write "Hello" the Server would reply with "World". It doesn't seem to work though. I got to the point where the client can write a message and server would say "Recieved the following message from the Client: " and it would print out the message after that.

    My next and final step would be: if that message is Hello, then print out World back to Client. I have no idea how to do this though and I've tried for nearly 1,5 hour. This is how the server code is right now:

    Code:
    {
    recv(sConnect, Message, sizeof(Message), NULL);
    strmessage = Message;
    	cout << "Received the following message from the Client " << Message << endl;
    			getchar();
    
    if(Message == "Hello"){
    answer = send(sConnect, "World",6,NULL);
    }
    	} while(Message != "Exit");
    It doesn't seem to work though :/
    Last edited by Moskis; 06-27-2012 at 02:16 PM.

    C++ WinSock if statement, send message back.
  2. #2
    cha0sbg's Avatar Active Member
    Reputation
    28
    Join Date
    May 2012
    Posts
    109
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the strcmp function.
    Code:
    { 
    recv(sConnect, Message, sizeof(Message), NULL);
             strmessage = Message; //Maybe this is a std::string ?
                          cout << "Received the following message from the client " << Message << endl;
                                 getchar();
    
    If( strcmp(strmessage.c_str(), "Hello") == NULL)
          answer = send(sConnect, "World", 6, NULL);
    
    
    }while(Message != "Exit");

  3. #3
    Moskis's Avatar Member
    Reputation
    13
    Join Date
    Nov 2008
    Posts
    38
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by cha0sbg View Post
    Try using the strcmp function.
    Code:
    { 
    recv(sConnect, Message, sizeof(Message), NULL);
             strmessage = Message; //Maybe this is a std::string ?
                          cout << "Received the following message from the client " << Message << endl;
                                 getchar();
    
    If( strcmp(strmessage.c_str(), "Hello") == NULL)
          answer = send(sConnect, "World", 6, NULL);
    
    
    }while(Message != "Exit");
    doesn't seem to work :/ Everything works except for the if part.

  4. #4
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    1) Do not write "World" into the function... use a char* ...

    2)cout answer to see if the packet was received by the host. It should display a 6.

    3)What does your client code look like? Need more info

  5. #5
    Moskis's Avatar Member
    Reputation
    13
    Join Date
    Nov 2008
    Posts
    38
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Server: Moskis's Server Code - Pastebin.com

    Client: Moskis's Client Code - Pastebin.com

    I am not very familiar with C++ yet so please explain slowly!

  6. #6
    DarkLinux's Avatar Former Staff
    CoreCoins Purchaser Authenticator enabled
    Reputation
    1627
    Join Date
    May 2010
    Posts
    1,846
    Thanks G/R
    193/539
    Trade Feedback
    16 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I only put like 2 or 3 min into it...

    Filebeam - Beam up that File Scottie!

    If you need more help, pm me your Skype or IM...
    Last edited by DarkLinux; 06-30-2012 at 02:01 AM.

  7. #7
    Master674's Avatar Elite User
    Reputation
    487
    Join Date
    May 2008
    Posts
    578
    Thanks G/R
    2/23
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <something used to be here... its gone now>
    Last edited by Master674; 10-15-2012 at 12:52 PM.

Similar Threads

  1. Send messages with Larger Letters! 2x ~
    By wickermanz in forum World of Warcraft Exploits
    Replies: 20
    Last Post: 03-04-2025, 10:35 PM
  2. [Buying] WTB 2-3 mil AD on Beholder via verified paypal please send message or leave reply
    By Grimfel in forum Neverwinter Buy Sell Trade
    Replies: 0
    Last Post: 05-24-2013, 05:25 PM
  3. [MaNGOS] send Auto Message
    By Moha4445 in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 04-15-2010, 03:05 AM
  4. Send a message to the Other Side
    By Kiloch in forum World of Warcraft Exploits
    Replies: 17
    Last Post: 01-22-2008, 09:52 PM
All times are GMT -5. The time now is 05:15 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search