![]() |
|
connect: Transport endpoint is already connected |
Cody Harris
Member #4,406
March 2004
![]() |
Here's the code: if (!isconnected){ printf("Connecting to %s\n",inet_ntoa(outlink_addr.sin_addr)); if (connect(outsock, (struct sockaddr *)&outlink_addr,sizeof(struct sockaddr)) == -1) { perror("connect"); //close(outsock); //exit(1); }else{ printf("Connected to %s (%d)\n",inet_ntoa(outlink_addr.sin_addr),outsock); FD_SET(outsock, &master); // add to master set if (outsock > fdmax) { // keep track of the maximum outsock = newfd; } isconnected = 1; } } And the output: Quote:
Unreal2Hybrid: new connection from 192.168.0.2 on socket 4 I can't figure out why it can't reconnect (it connects once, and only once, do I need to reset the struct or something?). And yes, this is using select, a modified select thingy from Beej. If you want I can post the entire code... --------------------------------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Theres a nice option called something like: SO_REUSEADDR. -- |
ReyBrujo
Moderator
January 2001
![]() |
Most probably the problem is in the bind, not the connect. It is an operative system issue. If you don't close the socket correctly (in example, press CTRL-C to end the program), the port is never freed. In Linux there used to be a delay of around 30 seconds-1 minute until the OS freed the socket and you were able to bind it again. -- |
Cody Harris
Member #4,406
March 2004
![]() |
Adding didn't work, it still complains... Do I have to reset the struct or something... --------------------------------- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Heres a little function I found and modified:
The log_* functions are mine, not libc or anything... Oh, and note, this is for a server style port IIRC. -- |
ReyBrujo
Moderator
January 2001
![]() |
How is the server code? It is listening for more connections? -- |
Cody Harris
Member #4,406
March 2004
![]() |
The server listens for connections, and if it find that when a client connects that it's not connected to another server, then it connects to it... I want it to reconnect to that socket if the connection is lost. EDIT: Why do you have to bind when connecting to something else? --------------------------------- |
ReyBrujo
Moderator
January 2001
![]() |
The code is old, you don't want to open a new port everytime you connect to something You should show the server code, though. The client should not have problem no matter how many they are. -- |
Cody Harris
Member #4,406
March 2004
![]() |
I edited it so that it recalled the socket thingy...
--------------------------------- |
ReyBrujo
Moderator
January 2001
![]() |
Hmm... close the old socket before creating a new one. And you meant reusing a socket to connect? Ah... I misunderstood, sorry. -- |
Cody Harris
Member #4,406
March 2004
![]() |
The old one is automatically closed on error or disconnect. This seems to work though. --------------------------------- |
ReyBrujo
Moderator
January 2001
![]() |
Hmm... really? It frees the descriptor? Geez... it must have changed since the last time I did some real network programming then... -- |
Cody Harris
Member #4,406
March 2004
![]() |
Yeah, it reuses file descriptors, the lowest one free (hense if you close stout and open a new file, all stout will go to the file... That's the logic between piping stout, you close it then you ddup it or whatever... --------------------------------- |
|