Thread: Connecting to Server

  1. #31
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    What you do in the client will not change the server. You are still writing on the socket, whether you do it through ws_fdw or through ws_sockfd.

    Is it working?

  2. #32
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by osal
    I will, but should it take this long to receive, i mean its been sitting here for a while
    __ No! __

  3. #33
    Registered User
    Join Date
    May 2004
    Posts
    215
    Here's where i posted my code.

    http://sourcepost.sytes.net/sourcevi...ource_id=14723

    It's almost time for my lunch, I'm going to leave in about 20, and ill be back in an hour. so around 12:40 my time ill be going for lunch, i hope youll still be available by the time i come back.

  4. #34
    Registered User
    Join Date
    May 2004
    Posts
    215
    The client.c program has been sitting here forever, and it hasnt gotten anything back. could it be possible that the program is frozen?

  5. #35
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> It's almost time for my lunch, I'm going to leave in about 20, and ill be back in an hour. so around 12:40 my time ill be going for lunch, i hope youll still be available by the time i come back. <<

    No, I'll be gone, but I'll have alook at the new source code first.

    >> The client.c program has been sitting here forever, and it hasnt gotten anything back. could it be possible that the program is frozen? <<

    Well, it's waiting to receive data which is not coming, so you could call it frozen!

  6. #36
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    1. You missed my post on why your ws_putline() is wrong.

    2.
    Code:
    00650:         printf("Sending authorization!\n");
                   //sprintf(line, "%s %s %s %s\n","STP",PASSWD,VERSION,"stpc"); // sets line to the ip, password, version, and interface
                   strcpy(line, "STP stpisgreat 1.4 stpc\n");
                   ws_putline(line);
    You are not finishing the string with a new line here. Add the highlighted portion. The server is probably waiting for a new line character in the call to fgets() and so is not sending a reply.

    Let me know how you get on.

  7. #37
    Registered User
    Join Date
    May 2004
    Posts
    215
    OK, i put that in, now it just does the same thing as it was before, its just not connecting.

  8. #38
    Registered User
    Join Date
    May 2004
    Posts
    215
    Actually its almost being connected, whats getting copied to line is just Connected instead of CONNECTED\n

  9. #39
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Yep, I just realised that my ws_getline() is removing the new line character. Here is a corrected version.
    Code:
    int ws_getline(char *str, int maxlen)
    {
    	int total = 0;
    
    	while (total < maxlen - 1)
    	{
    		/* Get a character */
    		int ret = recv(ws_sockfd, str, 1, 0);
    
    		if (ret == SOCKET_ERROR)
    		{
    			printf("recv() failed with error %d\n", WSAGetLastError());
    			break;
    		}
    		else if (ret > 0)
    		{
    			/* Increment received character count */
    			total++;
    			/* Check if we are finished this line */
    			if (*str++ == '\n') break;
    		}
    	}
    
    	*str = '\0';
    
    	return total;
    }
    It should finally work!

  10. #40
    Registered User
    Join Date
    May 2004
    Posts
    215
    Cool, it connects, now I gotta figure out how to fix the new error with. After it connects successfully, i get an error that states this :

    "error message: unknown byte order on client"

    So im going to try to figure out why its doing that. But thank you very much for all of your help! Would it be too much to ask if i could ask you more questions on my code?

    thanks

  11. #41
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Other improvements to note (sorry if these have been covered before):

    - Prototype your functions properly
    It's no good prototyping a function unless you're going to state what parameters it takes. So, this type of thing:
    >void open_waveserver();
    >void close_waveserver();
    >int ws_getline();
    is no good, use
    >void open_waveserver(char *);
    >void close_waveserver(void);
    >int ws_getline(char *, int);
    and fix all the others.
    Also, all the #include statements should come before the prototypes.

    - Function err().
    This function needs a variable number of arguments. Here's a sample of a more suitable implementation:
    Code:
     void err(int mode, char *fmt, ...)
     {
       va_list arglist;
       va_start(arglist, fmt);
       
       printf ("Mode: %d : WSAGetLastError: %d\n", mode, WSAGetLastError());
       vfprintf(stderr, fmt, arglist);
       va_end(arglist);
     
       if (mode == FATAL)
       {
     	exit(-1);
       }
     }
    The same kind of thing goes for the report() function.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #42
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Sorry, the ws_getline I posted is still not quite right. Here is the corrected version:
    Code:
    int ws_getline(char *str, int maxlen)
    {
    	int total = 0;
    
    	while (total < maxlen - 1)
    	{
    		/* Get a character */
    		int ret = recv(ws_sockfd, str, 1, 0);
    
    		if (ret == SOCKET_ERROR)
    		{
    			printf("recv() failed with error %d\n", WSAGetLastError());
    			break;
    		}
    		else if (ret > 0)
    		{
    			/* Increment received character count */
    			total++;
    			/* Check if we are finished this line */
    			if (*str++ == '\n') break;
    		}
    		else
    		{
    			break;
    		}
    	}
    
    	*str = '\0';
    
    	return total;
    }
    After it connects successfully, i get an error that states this :

    "error message: unknown byte order on client"
    Can you confirm that you have corrected the ws_putline() function? If not , it would be causing that error. Could you also post the new code(preferably with the corrections suggested by Hammer)?

  13. #43
    Registered User
    Join Date
    May 2004
    Posts
    215
    Well, i just added the
    Code:
    else
    {
       break;
    
    }
    now it goes it just keeps outputing the error over and over. The problem is within the receive() function in my program. I dont know how to fix it, it is between lines of 00400 and 00520.

    here's the site where my code is located at.

    http://sourcepost.sytes.net/sourcevi...ource_id=14735

    Thanks for all your help.

  14. #44
    Registered User
    Join Date
    May 2004
    Posts
    215
    One more thing. The error i do get states this:

    "Error message: unknown byte order format"

    and in the code before it hits the receive function, we do this so the server can establish teh byte order.

    Code:
     /* send a binary sample so the server can establish byte order */
    
    		
    	  two= 2;
    	  ws_putdata(&two,4);
    	  fflush(ws_fdw);
    	  printf("We have now set up the byte order!\n");

  15. #45
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your ws_putline() is wrong! This is the third or fourth time I have pointed that out! Because you are sending the data twice in ws_putline() the server is not reading the two when it should. Here is a correct implementation of ws_putline():
    Code:
    void ws_putline(char *str)
       {
    	int n = send(ws_sockfd, str, strlen(str), 0);
    
    	if (n == SOCKET_ERROR)
    	{
    		printf("send() failed with error %d\n", WSAGetLastError());
    	}
       }
    That should get rid of the "unknown byte order format" error.

    Then, go to line 55 and delete this line:
    Code:
             FILE *ws_fdr, *ws_fdw;  // file read-in and write-out
    We can't not use these successfully. So you will get warnings where you are trying to use them. Also delete this line:
    Code:
            int fd_rd;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. access violation when connecting to server
    By happyclown in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-10-2009, 12:46 AM
  2. connecting to server with wrong port
    By liri in forum Networking/Device Communication
    Replies: 3
    Last Post: 11-13-2007, 03:52 AM
  3. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM