-2

How can I check the status of remote end with the help of socket descriptor in vxworks. I am using TCP connection.

Thangaraj
  • 3,038
  • 7
  • 40
  • 43

3 Answers3

0

VxWorks uses the BSD Sockets API. When the remote station has terminated a connection I/O functions such as read() and write() functions return an error status (-1 for read/write) and set errno.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thanks for your reply; actually I want to know the status of socket descriptor without issuing read/write function. Are there any methods to achieve this? – Thangaraj Nov 12 '10 at 14:16
  • You cannot know the status of a remote system unless and until you attempt to communicate with it. There is no automatic polling in a TCP/IP connection. – Clifford Nov 12 '10 at 19:43
0

On at least some BSD-derived stacks I have worked with, you can check whether the other end has closed using getpeername(). On supporting stacks this will return -1 and set ENOTCONN if the other end has closed its half of the connection.

This allows you to query whether the other end has called close() without having to make a socket read call. Contrary to what has been previously stated, it is possible to find this out from the IP stack without initiating some connection to the other end, because the IP stack receives a FIN notification when the other end closes its half of the connection. This information can then be used by the stack to notify future getpeername() callers that the other end has closed.

ukembedded
  • 361
  • 1
  • 4
-1

Please refer the post:- how to restrict number of connections in client server program

Community
  • 1
  • 1
Thangaraj
  • 3,038
  • 7
  • 40
  • 43