Why the TCP server once received a read error [the Read() function has exit()], then exit the program? It will happen when a client is sending data and shutdown abnormally.
The same problem with writen().
Is it possible to change the codes like this? Then any disadvantage about modified codes?
Code:
if (FD_ISSET(sockfd, &rset)) {
if ( (n = Read(sockfd, buf, MAXLINE)) <= 0) {
/*4connection closed by client */
if ( n == 0 ) {
puts( "Client hung up!" );
} else {
puts( "Read error!" );
}
Close the socket when error or hung up.
Close(sockfd);
FD_CLR(sockfd, &allset);
client[i] = -1;
} else
Writen(sockfd, buf, n);
ssize_t Read(int fd, void *ptr, size_t nbytes) {
ssize_t n;
if ( (n = read(fd, ptr, nbytes)) == -1)
puts("read error");
return(n);
}
void Writen(int fd, void *ptr, size_t nbytes) {
if (writen(fd, ptr, nbytes) != nbytes)
puts("writen error");
}
hello socket programming expert,
I having difficulties in understanding how select() function in socket programming work.... I'm trying to create my own peer-to-peer chat or file transfer program by using the select() function.... Therefore does anyone had any tutorial or source code that... (4 Replies)
I have a socket and a message queue over which i am trying to multiplex input using select().
When data comes over socket the select works but when it comes over message queue the select is not detecting it .
Create_Q gets the identifier of the messege queue.
... (1 Reply)
Hi,
I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime.
To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
I need clarification on whether it is okay to set socket options on a listening socket
simultaneously when it is being used in an accept() call?
Following is the scenario:-
-- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
I have created two sockets and binded both. My requirement is that 2nd socket must send/ recv data only on expiration of timeval(tv). but the 1st socket must keep on send/recv the data without waiting for the 2nd socket completion......
I have posted my code below......
In this code the 2nd... (3 Replies)
Hello everyone.
I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)