System Errors:: System error 5 when using net view command in Vista. System Error code: 5, 53 and 66 Click Connect using a different user name, enter the username and password. http://www.chicagotech.net/systemerrors.htmHOME | I code the program that send char to other process but it have error in connect command. Sometime it can connect and send data but sometime it have error, invalid argument, in connect loop. I don't know that what wrong in my code.
void sent( unsigned short port , char ip[20] , char *buf )
{
int sockfd,a,sendsize;
struct sockaddr_in serv_addr;
/*
* Fill in the structure "serv_addr" with the address of the
* server that we want to connect with.
*/
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(ip); Windows NT Frequently Asked Questions (FAQ) Single File Version:: How can I change access permissions from the command line? Why do I get an error message when I try to run SQL 7 EM - MMC - Snap-in failed http://www.hitech-solutions.com/FAQ/faqcomp(1)/ntfaq_05JUN99.htmlHOME | SQLCMD fails with login timeout expired.:: When I run SQLCMD from a Command Prompt I get an. error: Hresult 0x2, level 16, State 1 I suggest that you try the following sqlcmd command to connect to http://www.developersdex.com/sql/message.asp?p=1926&r=5848747HOME |
serv_addr.sin_port = htons(port);
/*
* Open a TCP socket (an Internet stream socket).
*/
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket()");
return(errno);
}
/*
* Connect to the server. Modem AT Commands:: 4 ERROR Bad command. 5 CONNECT 1200 Connection established at Specifies action that should be taken when an attempt to connect in error-control mode fails. http://www.geniesys.net/solutions/Modem AT Commands.htmHOME |
*/
a=-1;
perror(ip);// tell where to connect
while (a < 0 )
{
a = connect(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr));
perror("connect()");
}
sendsize = send(sockfd, buf,(strlen(buf)+1), 0);
close(sockfd);
printf("end sending %s send size is %dn",ip,sendsize);
}
if want more code to understand pls email me, thankyou.
I believe, once connect() fails for real (by which I mean with a
non-transient error, such as EINTR, EINPROGRESS, etc.), the
socket FD becomes unusable from that point on... You just have
to close it down, and recreate it... The only valid use I've ever
seen for doing connect() within a loop is something like:
do {
i = connect (fd, &addr, addrlen);
} while ((i < 0) && (errno == EINTR));
But, other than that, I would say avoid ever calling connect() in
a loop... Or, at least, if you're going to, then close() the old FD
after a failure, and re-create a new one before the next connect()...
i was running this code :
int fd;
struct sockaddr_in serv_addr,cli_addr;
fd = socket(AF_INET,SOCK_STREAM,0);
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(8001);
while(connect(fd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
printf("nerror is %d",errno);
without delibrately running the server and the log i got was :
error is 111
error is 22
error is 22
error is 22
error is 22
error is 22
error is 22
error is 22
error is 22
.
.
.
can you please explain that why on only first call to connect i got the error ECONNREFUSED while for the calls after this i got EINVAL???
i think calling connect() in a loop is the problem. One connot call connect() on same socket fd more than once.
so if you want to call connect() in a loop then use new sockfd every time.
Everything seems to be fine... in fact, I just slapped it into a small program and ran it a half dozen times w/o problem except for a few compile warnings such as you doing a value return (of errno) from a void function...
So a bit of a silly question but the only thing that comes to mind... you are always passing in a dotted decimal address string to your function aren't you... since inet_addr will not do full name resolution... only conversion...
Michael
The socket descriptor they are using is not being re-used... the loop in the code is checking for a return value of -1 which is the error indicator... e.g. could not establish the connection and so forth...
Having said that... the loop is technically bad as it is shown... since it does not check for specific types of errors (EINTR etc.) which should cause a restart of the connect attempt and those which should cause an abort (no route etc.)... the latter which could under some impls cause the socket to "go bad"...
Michael
How much does getting a small tattoo on your hip/stomach hurt?
Do anyone else have an itchy anus? ?
|