Thread: At a loss

  1. #1
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43

    At a loss

    I've been plugging away with my sockets. I've set up tests, and read nothing. I've come to the conclusion something must be wrong when I start opening the sockets. As I've downloaded other example sources and edited them to use exactly what i've got to open to the address. This is what I have. Any help would be grand.

    Code:
            char szServer[] = "darkmists.org";
    	short nPort = 2222;
    	char hFrom[500];
    			
    
    	do_winsock();
    	          make_connection(szServer,nPort);
      	read_from_socket(hFrom,256);
    	printf("\nData received: %s", hFrom);
    	do_specs();
    	printf("specs sent. Initiating autorolling.\n\r");
    	check_autoroller();
    	close_connection();
    	shutdown_winsock();
    To error is human, to really foul things up requires a computer

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You need to do more debugging. Make sure you're getting connected. Check all return codes from socket related calls to ensure they worked, and take the appropriate action if they didn't; don't leave anything to chance. Use netstat to help prove the connection is up.

    If you still can't get it, go back to basics. Strip out as much code as possible, leaving only the networking bits. Then debug those on their own. Strip down further if you still can't find the problem. Then, when you start to make headway, put the application back together piece by piece, checking it still works at every step.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    Right on. I hadn't though of using netstat. I'm getting connected fine I know that. I've got checks for that. I just can't recieve anything other then a whole load of [[[[[[[[[['s I was just thinking maybe how I was getting the host and port was the problem. I'll keep plugging away. Thanks.
    To error is human, to really foul things up requires a computer

  4. #4
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    Actually. I was just using this because someone I knew already had a library. However since it doesn't work for me. I'm going back and redoing all the functions one at a time. Right now i've gotten it so I can actually recieve from the socket. Now i get a division sign and a smiley face when I try to send stuff, but it's a step forward. Also what would cause this to stop before everything is written?

    Code:
    #define MAXDATASIZE 700000
    
    int numbytes;
    char buf[MAXDATASIZE];
    
    if ((numbytes=recv(sockfd, buf, 9999, 0)) == -1) {
            printf("recv");
            return false;
        }
        else{
    	buf[numbytes] = '\0';
    	}
    	
    	printf("\n%s", buf);
    To error is human, to really foul things up requires a computer

  5. #5
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    This is what I use to send to the socket.

    Code:
    void write_to_socket(char * buf)
    {
       send(sockfd, buf, strlen(buf),0);
       return;
    }
    this is how i get the info to send and use write_to_socket.

    Code:
    //Name
    		printf("Name for character?\n\r");
    		fgets(name, sizeof(name), stdin);
    		if (name == '\0')
    		{
    			printf("Name was blank.\n\r");
    		}
    		else
    		{
    			write_to_socket(name);
    			write_to_socket(answer);
    		}
    	
    		//Password
    		printf("Give us a password.\n\r");
    		{
    			
    			fgets(password,sizeof(password),stdin);
    			write_to_socket(password);		
    			write_to_socket(password);
    		}
    I get the problem when i'm sending the password. I need to send it twice to verify it. Then we enter the smiley and division sign.
    To error is human, to really foul things up requires a computer

  6. #6
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    Can you just send text? ie send(sockfd, "yes", sizeof(buf), 0 );

    Also how do you send an enter key? just \r ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Economy crises, Job loss etc etc
    By ssharish2005 in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 01-27-2009, 03:08 PM
  2. conversion from double to float - loss of data
    By diyteam in forum C++ Programming
    Replies: 20
    Last Post: 03-04-2008, 02:59 AM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. Guaranteed weight loss
    By Glirk Dient in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-12-2004, 06:11 AM
  5. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM