Thread: Socket or send() problem?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    17

    Socket or send() problem?

    I posted another topic about needing to Multithread, and I got that workin' all fine and dandy, but now it seems that my socket is buggin' out.

    Problem:
    I'm connecting to an IRC server and trying to send/recieve whatever data that I need, but my send is acting kind of funny. Upon connecting to the server, I recieve the first message fine:

    :irc.XXX.com NOTICE AUTH :*** Found your hostname

    Therefore my recv is working just fine. But I then try to send the USER and NICK command to the IRC server (which should produce a crapload of messages from the server), but it doesn't seem to be going through. I know its not sending because my friend is hosting the IRC server, and can detect when someone sends the USER and NICK commands, and he is getting nothing when I supposively send. I am getting no response from the server when I try to send it data... not even an error message when I send some spam. Any help would be greatly appreciated.

    NOTE: I'm coding in Windows, using winsock2 library.

    Code:

    Socket connection, setup, etc.
    Code:
    	wVersionRequested = MAKEWORD( 2, 2 );
    	err = WSAStartup(wVersionRequested, &wsaData );
    
    	if(err != 0) {
    		printf("WSA startup fail.\n");
    	}
    	
    	
    	m_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    	if(m_socket == INVALID_SOCKET){
    		printf( "Error at socket(): %ld\n", WSAGetLastError() );   
    	}
    
    	clientService.sin_family = AF_INET;
    	clientService.sin_addr.s_addr = inet_addr( hostToIP("irc.XXX.com") );
    	clientService.sin_port = htons( 6667 );
    
    	if ( connect( m_socket, (SOCKADDR*) &clientService,
    			   sizeof(clientService) ) == SOCKET_ERROR) {
    		printf( "Failed to connect.\n" );
    		WSACleanup();
    	} else {
    		printf("Connection Success!\n\n");
    	}
    send() loop:
    Code:
    	do {
    		if((s_ready = select(0, NULL, &fd, NULL, NULL)) != SOCKET_ERROR) {
    			gets(input);
    			if(strstr("/q", input)) break;
    			bSent = send(m_socket, input, sizeof(char)*strlen(input), 0);
    			printf("Sent(%d): %s\n", bSent, input);
    			flusher(input);
    		}	
    	} while (1);
    recv() loop:
    Code:
    	while(go == 1) {
    		if((err = ioctlsocket(m_socket, FIONREAD, &l)) == SOCKET_ERROR) {
    			printf("Error: ioctlsocket(). error: %d\n", WSAGetLastError());
    			break;
    		} else if(l > 0) {
    				printf("Trying to recieve...\n");
    				bytesIn = recv(m_socket, rec, BUFFMAX, 0);
    				if(bytesIn > 0) {
    				
    					printf("%s", rec);
    					rec[0] = '\0';
    				}
    		}
    		ready = 1;
    	}
    The two latter snippets of code are running simotaneously via multithreading. This program shoould essentially be a telnet program untill I get some command parsing going on .

    Note 2: flusher() and hostToIP() are functions that I have created.
    Last edited by Achy; 06-09-2006 at 12:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. sending n no of char data uning send() function,
    By thebrighter in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2007, 12:26 PM
  3. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  4. C socket problem
    By TeMpEsT-9 in forum C Programming
    Replies: 6
    Last Post: 07-27-2002, 12:53 PM
  5. stream socket problem
    By WL in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 11:07 PM