|
-
March 11th, 2005, 02:15 PM
#1
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."
-
March 11th, 2005, 04:26 PM
#2
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
-
March 11th, 2005, 05:35 PM
#3
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."
-
March 14th, 2005, 10:26 AM
#4
Re: 1 to 1 chat program
 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.
-
March 14th, 2005, 06:07 PM
#5
-
March 15th, 2005, 11:03 AM
#6
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.
-
March 15th, 2005, 03:04 PM
#7
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."
-
March 16th, 2005, 10:15 AM
#8
Re: 1 to 1 chat program
good luck! hows the weather in alberta
-
March 16th, 2005, 05:05 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|