TCP Socket Programming
An Introduction with Examples in C |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
int accept(int fd, struct sockaddr *addr, socklen_t *addrlen)
fd
|
The file descriptor of the passive socket |
addr
|
The address of the active socket that initiated the connection (or NULL if not needed) |
addrlen
|
The length of addr |
Return | The file descriptor for the connection on success; -1 on error |
Notes: (1) accept()
blocks (unless there are pending connections).
(2) The file descriptor that is returned has an associated active
socket. In other words, an active socket is created by the passive
socket each time accept()
returns.
int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
fd
|
The file descriptor of the active socket making the request |
addr
|
The address of the passive socket |
addrlen
|
The length of the address of the passive socket |
Return | 0 on success; -1 on error |
telnet
:
telnet
for Other Purposes:
telnet
uses TCP at the transport
layer and reverts to "old line-by-line mode" if the remote
party doesn't support TELNET, it can be used to communicate
with other applications that use TCPtelnet
) sends a course coderead()
and write()
may read/write
fewer characters than were requested (and return the number
actually read/written)