Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   help with displaying message (http://www.programmingforums.org/showthread.php?t=10664)

d_heyzie Jul 8th, 2006 11:05 AM

help with displaying message
 
hi, im trying to learn how to use winsock in C++ programs so ive tried to make a small client/server thing where the client sends a message and the server responds. My problem is that, although they are connecting, and i think they are probably recieving the messages, i cant get the recieved message to be displayed on the console window.

:

send(sockfd, *ping, 4, 0);
   
    if(errno == -1)
    {
            cout <<"Send failed!" << endl;
    }
    else
    cout <<"Client> " << *ping << endl;
   
    recv(sockfd, *buf, 256, 0);
   
    if(errno == -1)
    {
            cout <<"Recv failed!" << endl;
    }
    else
    cout <<"Server> " << *buf << endl;

(Section of Client code where i believe the problem lies)

:

  recv(new_sockfd, *buf, 256, 0);
    if(errno == -1)
    {
            cout <<"failed to recieve" << endl;
    }
    else
    cout <<"Client> " << *buf << endl;
   
   
    send(new_sockfd, *pong, 4, 0);
    if(errno == -1)
    {
            cout <<"Failed to send msg!" << endl;
    }
    else
    cout <<"Server> " << *pong << endl;

(Section of Server code where i believe the problem lies)

Client OUTPUT:
Client> ping
Server> (some wierd stuff that im not gonna bother to write)

Server OUTPUT:
Client> (blank)
Server> pong

HAYELLP!!!

Cache Jul 8th, 2006 11:55 AM

You should show how 'ping', 'pong', and 'buf' are declared. The dereferencing you're doing doesn't look right, but it depends on what 'buf' ect is to say what is right.

d_heyzie Jul 8th, 2006 8:36 PM

yeah, long after i posted i thought i shoulda probably done that, but i fixed it anyway. I had to change the type i was using from char* to char. I still have a little odd output but i should be able to fix that. ty


All times are GMT -5. The time now is 12:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC