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?
Printable View
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?
__ No! __Quote:
Originally Posted by osal
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.
The client.c program has been sitting here forever, and it hasnt gotten anything back. could it be possible that the program is frozen?
>> 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!
1. You missed my post on why your ws_putline() is wrong.
2.
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.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);
Let me know how you get on.
OK, i put that in, now it just does the same thing as it was before, its just not connecting.
Actually its almost being connected, whats getting copied to line is just Connected instead of CONNECTED\n
Yep, I just realised that my ws_getline() is removing the new line character. Here is a corrected version.
It should finally work!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;
}
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
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:
The same kind of thing goes for the report() function.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);
}
}
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;
}
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)?Quote:
After it connects successfully, i get an error that states this :
"error message: unknown byte order on client"
Well, i just added the
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.Code:else
{
break;
}
here's the site where my code is located at.
http://sourcepost.sytes.net/sourcevi...ource_id=14735
Thanks for all your help.
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");
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():
That should get rid of the "unknown byte order format" error.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());
}
}
Then, go to line 55 and delete this line:
We can't not use these successfully. So you will get warnings where you are trying to use them. Also delete this line:Code:FILE *ws_fdr, *ws_fdw; // file read-in and write-out
Code:int fd_rd;