130 likes | 236 Views
Remote Shell. CS230 Project #4 Assigned : 2006. 05. 15 Due date : 2006. 05. 29. server. socket(). bind(). client. socket(). listen(). accept(). connection. connect(). request data. send(). recv(). reply data. recv(). send(). Socket. Socket: a software abstraction
E N D
Remote Shell CS230 Project #4 Assigned : 2006. 05. 15 Due date : 2006. 05. 29
server socket() bind() client socket() listen() accept() connection connect() request data send() recv() reply data recv() send() Socket • Socket: a software abstraction • designed to provide a standard API for sending and receiving data across a computer network • c.f.) pipe, file, shared memory • Sockets are designed to accommodate virtually any networking protocol (i.e. TCP/IP and UDP/IP). • Implemented in many different programming languages and for most operating systems.
IP, Port, and Internet Protocol • IP: • A address assigned for network interface card • 32bits address • Port • End-point of a communication operation • 16-bit number • UDP • Connectionless • Unreliable • Un-ordered packet protocol • TCP • Connection setup • Provide reliable connection • In-order byte stream protocol • Congestion Control
Functions (1/3) • int socket(int domain, int type, int protocol) • create socket • type • SOCK_STREAM: TCP • SOCK_DGRAM: UDP • int bind(int sockfd, const struct sockaddr *address, size_t address_len) • associate a socket with an IP address and port number • int listen(int sockfd, int n) • tell a socket to listen for incoming connections
Functions (2/3) • int accept(int sockfd, struct sockaddr *address, size_t *address_len) • accept an incoming connection on a listening socket • int connect(int sockfd, const struct sockaddr *address, size_t address_len) • connect a socket to a server • ssize_t recv(int sockfd, void *buf, size_t len, int flag) • receive data on a socket
Functions (3/3) • ssize_t send(int sockfd, const void *buf, size_t len, int flags) • send data out over a socket • int close(int sockfd) • close a socket descriptor
Specification (1/3) • Enhance your own shell to allow remote access of single client/server model • Supplement built-in server/client commands for your shell • e.g.) $server 12345 $client 127.0.0.1 12345 • Remote access • Server receives commands from client’s standard input • The server executes the commands • The server returns its standard output to the client • How often inputs/outputs are exchanged between client and server? Standard input Standard output client server
Specification (2/3) • Supplements file transfer commands • ‘put filename’ command • Upload client’s file from client to server • If server already has a file of the same name, overwrite the existing file • ‘get filename’ command • Download server’s file from server to client • If client already has a file of the same name, overwrite the existing file • Allow ‘!’ as generic console ftp programs do to execute client’s side commands
Specification (3/3) • Details • Use TCP connection • Do not use threads yet • Compile • -lxnet option
Reference • http://beej.us/guide/bgnet/