I use connect() to connect to a particular server.
If i want to reuse the socket and connect to another server, what should i do..
What i am doing currently is:
//Create a socket and bind to a port
//then
tcnt = 0;
while(1)
{
servAddr.sin_family = AF_INET;
inet_pton(AF_INET, ip_addr[tcnt], &servAddr.sin_addr);
servAddr.sin_port = htons(SERVPORT);
bytes = connect(sdServerLoad, (struct sockaddr *) &servAddr, sizeof(servAddr));
if(bytes < 0)
{
perror("connect");
continue;
}
.
.
.
.
tcnt++;
}
The first loop executes fine, but during the second round of execution of the loop..it throws me an error "connect: Transport endpoint is already connected"
Why is this n how can i solve it..