No errors when compiling and I can comment out most of the main function and it still frezzes.
Remove the SDL parts and it won't freeze up but then again the SDL is most of the program.


CODE:

//Main.cpp
#include <SDL.h>
#include <iostream>
#include "Socket.h"
#include <fstream>
#include <string>

using namespace std;

SDL_Surface *screen;
SDL_Event event;

void apply_surface( int x, int y, SDL_Surface* source)
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    //Blit the surface
    SDL_BlitSurface( source, NULL, screen, &offset );
    
    SDL_Flip(screen);
    
    
}

void clearscreen(){
            SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) );
}













class Dot
{
    private:
    //The X and Y offsets of the dot
    int x, y;



    public:
    //Initializes the variables
    Dot();

    //Takes key presses and adjusts the dot's velocity
    void handle_input(int xz, int yz);

    //Moves the dot
    void move();

    //Shows the dot on the screen
    void show();
    
    int getx();
    int gety();
};






Dot::Dot()
{
    //Initialize the offsets
    x = 0;
    y = 0;

}



void Dot::handle_input(int xz,int yz)
{
x = xz;
y = yz;
}

void Dot::show()
{
SDL_Rect basd;
basd.w = 10;
basd.h = 10;
basd.y = y;
basd.x = x;
SDL_FillRect( screen, &basd, SDL_MapRGB( screen->format, 0x00, 0x99, 0x00 ) );
}


int Dot::getx(){
    return x;
}
int Dot::gety(){
    return y;
}


int main(int argc, char* args[])
{
              screen = SDL_SetVideoMode(500,500,32,0);
      //Dot ase;
    int choice;
    int port = 4521;
    //char *ipAddress = "127.0.0.1";
    string ipAddress;
    bool done = false;
    char recMessage[STRLEN];
    char sendMessage[STRLEN];


        //Client

        
        ClientSocket sockClient;

        sockClient.ConnectToServer("127.0.0.1", 4753 );


        //Connected

//74.76.149.190

          string jppa;
          int pos1,pos2;




        while ( true )
        {     

sockClient.RecvData(recMessage,STRLEN);
string sad = recMessage;

if(strlen(sad.c_str()) > 6){

int pos = sad.find("BA"); 
string xc,yc;

xc = sad.substr(0,3); 
yc = sad.substr(pos+3);

int ll,kk;

ll = atoi(xc.c_str());
kk = atoi(yc.c_str());


}


SDL_Delay(150); 
}



        }

Page not found?

Page not found?

try the links again -- they worked ok for me.

Anything that helps?

what is SDL ?
where is socket.h?

I need to compile and run your program is you expect my help.

BTW I did add SDL_Init() to it. I used the eveything flag.

Here is Socket.ccp code:

//Socket.cpp
#include "Socket.h"

Socket::Socket()
{
    if( WSAStartup( MAKEWORD(2, 2), &wsaData ) != NO_ERROR )
    {
system("pause");
        WSACleanup();
        exit(10);
    }

    //Create a socket
    mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

    if ( mySocket == INVALID_SOCKET )
    {
system("pause");
        WSACleanup();
        exit(11);
    }

    myBackup = mySocket;
}

Socket::~Socket()
{
    WSACleanup();
}

bool Socket::SendData( char *buffer )
{
    send( mySocket, buffer, strlen( buffer ), 0 );
    return true;
}

bool Socket::RecvData( char *buffer, int size )
{
    int i = recv( mySocket, buffer, size, 0 );
    buffer[i] = '\0';
    return true;
}

void Socket::CloseConnection()
{
    //cout<<"CLOSE CONNECTION"<<endl;
    closesocket( mySocket );
    mySocket = myBackup;
}

void Socket::GetAndSendMessage()
{
    string message;
    //without this, it gets the return char from the last cin and ignores the following one!
cin>>message;
char msg[STRLEN];
strcpy(msg,message.c_str());
    SendData( msg );
}

void ServerSocket::StartHosting( int port )
{
     Bind( port );
     Listen();
}

void ServerSocket::Listen()
{
    //cout<<"LISTEN FOR CLIENT..."<<endl;
    
    if ( listen ( mySocket, 1 ) == SOCKET_ERROR )
    {
        cerr<<"ServerSocket: Error listening on socket\n";
        system("pause");
        WSACleanup();
        exit(15);
    }
    
    //cout<<"ACCEPT CONNECTION..."<<endl;
    
    acceptSocket = accept( myBackup, NULL, NULL );
    while ( acceptSocket == SOCKET_ERROR )
    {
        acceptSocket = accept( myBackup, NULL, NULL );
    }
    mySocket = acceptSocket;
}

void ServerSocket::Bind( int port )
{
    myAddress.sin_family = AF_INET;
    myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" );
    myAddress.sin_port = htons( port );
    
    //cout<<"BIND TO PORT "<<port<<endl;

    if ( bind ( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress) ) == SOCKET_ERROR )
    {
        cerr<<"ServerSocket: Failed to connect\n";
        system("pause");
        WSACleanup();
        exit(14);
    }
}

void ClientSocket::ConnectToServer( const char *ipAddress, int port )
{
    myAddress.sin_family = AF_INET;
    myAddress.sin_addr.s_addr = inet_addr( ipAddress );
    myAddress.sin_port = htons( port );
    
    //cout<<"CONNECTED"<<endl;

    if ( connect( mySocket, (SOCKADDR*) &myAddress, sizeof( myAddress ) ) == SOCKET_ERROR )
    {
        cerr<<"ClientSocket: Failed to connect\n";
        system("pause");
        WSACleanup();
        exit(13);
    } 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.