Click to See Complete Forum and Search --> : 1 to 1 chat program
barrensoul
March 11th, 2005, 01:15 PM
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.
drewdaman
March 11th, 2005, 03:26 PM
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
barrensoul
March 11th, 2005, 04:35 PM
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)
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 );
}
drewdaman
March 14th, 2005, 09:26 AM
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.. :p
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!
barrensoul
March 14th, 2005, 05:07 PM
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.
drewdaman
March 15th, 2005, 10:03 AM
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.
barrensoul
March 15th, 2005, 02:04 PM
I'll get it to work in DOS :) some how :D
drewdaman
March 16th, 2005, 09:15 AM
good luck! hows the weather in alberta
barrensoul
March 16th, 2005, 04:05 PM
bloody miserable, snow for the next week or so.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.