⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.h

📁 java socket server,对初学者很好的参考意义
💻 H
字号:
/*   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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -