Hi guys, I am trying to make a chat bot on Omegle, (sort of line SmarterChild on MSN, but for Omegle). Anyway, my problem is when I send my HTTP post, I am not receiving any data. I call recv, but it does not send me any data. When I send the same headers with telnet, everything works fine.

Here is my source code, I think I have to add something at the end of my string. Omegle uses TwistedWeb as their web server. Here is my source code:

main.h

#ifndef main_h

#include <winsock2.h>
#include <windows.h>
#include <stdio.h>

char header1[] = "POST /start?rcs=1 HTTP/1.1\nHost: omegle.com\nUser-Agent: FireFox/1.0\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 0\n";

#define main_h
#endif

main.cpp

#include "main.h"

int OmegleBot(char* header1);

int main()
{
    OmegleBot(header1);
    system("pause");
    return 0;
}

int OmegleBot(char* header1)
{
    INT             nret;
    SOCKADDR_IN     addr;
    LPHOSTENT       hostEntry;
    WSADATA         wsaData;
    SOCKET          Socket;
    CHAR            OmegleID[20];
    CHAR*           token;
    CHAR            recvData[256];

    if( WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR )
    {
        WSACleanup();
        return 0;
    }

    hostEntry = gethostbyname("omegle.com");
    if( !hostEntry )
    {
        WSACleanup();
        return 1;
    }

    Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if( Socket == INVALID_SOCKET )
    {
        WSACleanup();
        return 2;
    }

    addr.sin_family = AF_INET;
    addr.sin_addr = *( (LPIN_ADDR)*hostEntry->h_addr_list );
    addr.sin_port = htons(80);

    nret = connect( Socket, (LPSOCKADDR)&addr, sizeof(struct sockaddr) );
    if( nret == SOCKET_ERROR )
    {
        WSACleanup();
        return 3;
    }

    send(Socket, header1, strlen(header1), 0);
    printf(header1);
    printf("\n\n");
    recv(Socket, recvData, 256, 0);  //Program is stuck here, doesnt recv anything.
    printf(recvData);

    WSACleanup();

}

To sum it all up, how come my program does not receive any data? What do I have to change to receive the response of my post?

Edited 3 Years Ago by mike_2000_17: Fixed formatting

http://www.daniweb.com/forums/post1157666.html#post1157666
You're presuming that send() and recv() deal with complete messages and are error free.

> printf(recvData);
You will get your ass handed to you on a plate if someone sends you a % character.
http://en.wikipedia.org/wiki/Format_string_attack

Further, recv() does NOT add a \0 to make it a string you can just pass to printf.

I am now checking to see if send > 0 and if recv > 0. However, I still have the same problem.

And ty for letting me know about format string attacks.

This article has been dead for over six months. Start a new discussion instead.