server.h

来自「java socket server,对初学者很好的参考意义」· C头文件 代码 · 共 66 行

H
66
字号
/*   a C++ socket server class    Keith Vertanen 11/98 */#define BUFFSIZE 64000#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <sys/types.h>#include <netinet/in.h>#include <netdb.h>#include <sys/socket.h>#include <sys/wait.h>class Server{  // class attibutes  public:		int port;	// the port I'm listening on	int dataport;	// the port I'm listening for datagrams on	int REVERSE;    // should be reverse the incoming/outgoing			// byte order, 0 is normal, 1 is reversed	  protected:			int sockfd;	               // listen on sock_fd	int datasockfd;	               // listen on datagram socket	int senddatasockfd;	       // datagram send socket	int new_fd;	               // new connection on new_fd	struct sockaddr_in my_addr;    // my address information        struct sockaddr_in their_addr; // connector's address information        struct sockaddr_in dest_addr;  // used for datagram sending, not				       // sure why we can't use their_addr, oh well	int sin_size;	double buffer[BUFFSIZE];	// reuse the same memory for buffer	double buffer2[BUFFSIZE];  // class methods  public:	Server(int, int);			// constructor with port #	void connect();			// accept a new connection	void closesocket();		// close the socket	void send_string(char *str);		// send a string to socket	void send_bytes(char *vals, int len);	        // send some bytes	void send_ints(int *vals, int len);	        // send some integers	void send_floats(float *vals, int len);		// send some floats	void send_doubles(double *vals, int len);	// send some doubles	void send_datagram(char *vals, int len);	// send a datagram packet	int recv_string(char *str, int max, char term); // recv a string	int recv_bytes(char *vals, int max);  		// recv bytes	int recv_ints(int *vals, int max);  		// recv ints	int recv_floats(float *vals, int max);  	// recv floats	int recv_doubles(double *vals, int max);  	// recv doubles	int recv_datagram(char *vals, int max);  	// recv datagram	void recv_ack();	void send_ack();};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?