C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 07-21-2006, 06:55 PM   #1
Registered User
 
Join Date: Jun 2005
Location: Philadelphia
Posts: 16
Unhappy IRC get/send messages help

Basically, I've decided to mess around with sockets and create a telnet style IRC client. However, I am having a problem with the program getting the chat from the server channel and simultaneously letting me enter chat to be sent. I've tried a few various ways on how to do this but they all either ended up getting the buffer and not letting me chat or letting me chat and not getting the buffer. The way that I am doing it so far is
Code:
	while(true)
	{
		while((recv(Socket, buffer, strlen(buffer), 0) != 0) || 
		      (recv(Socket, buffer, strlen(buffer), 0) != -1))
		{
		cout<<buffer;
		break;
		}
		memset(buffer, 0, strlen(buffer));
		cin>>cintext;
		strcpy(texttosend, "PRIVMSG #blahhh :");
		strcat(texttosend, cintext);
		strcat(texttosend, "\r\n");
		send(Socket, texttosend, strlen(texttosend), 0);
		memset(cintext, 0, 255); memset(texttosend, 0, 255);
	}
but it's not really letting me enter text/read simultaneously. I can't really logically think of how this would be implemented after trying tons of different approaches, if someone can help me out of this it would be greatly appreciated. Thanks.
RedZone is offline   Reply With Quote
Old 07-22-2006, 12:36 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,662
> recv(Socket, buffer, strlen(buffer), 0)
If you've cleared the buffer before, then strlen is going to return 0.
Use sizeof if your buffer is an array (not a pointer).

Eg.
Code:
while ( (n=recv(Socket, buffer, sizeof(buffer), 0)) > 0 ) {
  // Note that recv DOESN'T append a \0, so use 'n' to determine
  // what to do
}
if ( n == 0 ) {
  // closed
}
if ( n == -1 ) {
  // error
}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 07-22-2006, 03:27 PM   #3
Registered User
 
Join Date: Jun 2005
Location: Philadelphia
Posts: 16
Thanks for the help, fixed everything and it works just as I wanted it to.
RedZone is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spy++ view messages posted/sent to a control, or from it? hanhao Windows Programming 2 06-24-2007 11:07 PM
IRC, reading the stream Iyouboushi C# Programming 6 08-03-2006 05:34 PM
Sending windows messages Ideswa Windows Programming 2 03-02-2006 01:27 PM
Some help needed with IRC SaintK C++ Programming 2 04-04-2004 07:27 AM


All times are GMT -6. The time now is 06:12 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22