CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    1 to 1 chat program

    what I want to do is creat a small chat program that outputs to a console (DOS). the thing I don't know how to do is send that string data, I'm gonna go over the code in attachment on this post http://www.codeguru.com/forum/showthread.php?t=318600 but I don't see a rescieve on the client side in that source. Do I need to make both people client and server? or just combined them? all I need to know is how to send the message , I'd like to know what it is I need to know to do this and/or how to do this. I can handle the output to console and the management of data once it reaches its destination I just don't know how to get it there.

    Edit: TCP/IP of course.
    Last edited by barrensoul; March 11th, 2005 at 02:23 PM.
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  2. #2
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    628

    Re: 1 to 1 chat program

    what do you mean by 1 to 1? one person can talk to another person and that's it? or do you mean no 3 way chats (like on msn when you invite a third,fourth,....) person to chat?

    see if this helps: http://www.codeproject.com/Purgatory/Chat_Program.asp

  3. #3
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: 1 to 1 chat program

    bah screw it better to make one from scratch.

    Ok I've tought about this programm a bit more and I've hit a rather large snag, how do I have it listening for packets data and waiting for use input? is this where "multi threading" comes in?

    I've got a strange error, when I recieve data (an array of chars) there are no spaces. (I love you becomes Iloveyou)

    Code:
     char sendbuf[buffersize];
     char sendbuf2[buffersize];
     while(1)
     {
     cout<<"\ninput: ";
     ZeroMemory(sendbuf2,strlen(sendbuf2));
     cin>>sendbuf2;
     strcpy(sendbuf,sendbuf2);
     bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
     }
    Last edited by barrensoul; March 12th, 2005 at 12:36 AM.
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  4. #4
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    628

    Re: 1 to 1 chat program

    Quote Originally Posted by barrensoul
    Ok I've tought about this programm a bit more and I've hit a rather large snag, how do I have it listening for packets data and waiting for use input? is this where "multi threading" comes in?
    if what you mean by that is "how do you know when a socket is ready to receive" then you can use select. you would most likely use multithreading to accept multiple connections. Sockets can be used to communicate both ways... just use select to know whether a socket is ready to recieve (ie teh other end has actually sent some data)

    i just figured out hwo to use select recently..
    take a look at my post: http://www.codeguru.com/forum/showthread.php?t=331050

    you might find my second post there more useful than the first!
    Last edited by drewdaman; March 14th, 2005 at 10:31 AM.

  5. #5
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: 1 to 1 chat program

    close to what I meant I meant multi-threading because I don't wan't the chat to be one way, if the program is waiting for use input it won't be able to output since the output will be somewhere else in the code and other code dosn't exec when waiting for use input '

    but knowing that select thing will solve some of my port forwarding problem but not all for that I thank you.
    Last edited by barrensoul; March 14th, 2005 at 06:09 PM.
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  6. #6
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    628

    Re: 1 to 1 chat program

    hmm... well.. if its a console application then i guess multithreading with synchronization might work ..but it might not be the greatest thing... because if soemone at one end types a letter, goes away for a bit (without actually sending the messaeg), the incoming messages won't be displayed until the user actually sends the message- this would take away from a chat's "real-time nature". i can't think of a way to deal with this issue off the top of my head.. but you mgiht be able to! but if you have a gui (ie have separate areas for incoming and outgoing messages- like an msn chat window) then you should be able to do it without multithreading.

  7. #7
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: 1 to 1 chat program

    I'll get it to work in DOS some how
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  8. #8
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    628

    Re: 1 to 1 chat program

    good luck! hows the weather in alberta

  9. #9
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: 1 to 1 chat program

    bloody miserable, snow for the next week or so.
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured