📄 cnvsocket.h
字号:
//---------------------------------------------------------------------------
#ifndef CNVSocketH
#define CNVSocketH
#include "CNVtypes.h"
#include "CNString.h"
#include "Stream.h"
#define AOL "\r\n"
//---------------------------------------------------------------------------
////////////////////////////
// Socket implementation
// Create one or more VSocketSystem objects per application
class VSocketSystem
{
public:
VSocketSystem();
~VSocketSystem();
VBool Initialised() {return m_status;};
private:
VBool m_status;
};
// The main socket class
class VSocket
{
public:
// Constructor/Destructor
VSocket();
virtual ~VSocket();
////////////////////////////
// Socket implementation
// Create
// Create a socket and attach it to this VSocket object
VBool Create();
// Shutdown
// Shutdown the currently attached socket
VBool Shutdown();
// Close
// Close the currently attached socket
VBool Close();
// Bind
// Bind the attached socket to the specified port
// If localOnly is VTrue then the socket is bound only
// to the loopback adapter.
VBool Bind(const VCard port, const VBool localOnly=VFalse);
// Connect
// Make a stream socket connection to the specified port
// on the named machine.
VBool Connect(const VString address, const VCard port);
// Listen
// Set the attached socket to listen for connections
VBool Listen();
// Accept
// If the attached socket is set to listen then this
// call blocks waiting for an incoming connection, then
// returns a new socket object for the new connection
VSocket *Accept();
// GetPeerName
// If the socket is connected then this returns the name
// of the machine to which it is connected.
// This string MUST be copied before the next socket call...
VString GetPeerName();
// GetSockName
// If the socket exists then the name of the local machine
// is returned. This string MUST be copied before the next
// socket call!
VString GetSockName();
// Resolve
// Uses the Winsock API to resolve the supplied DNS name to
// an IP address and returns it as an Int32
static VCard32 Resolve(const VString name);
// SetTimeout
// Sets the socket timeout on reads and writes.
VBool SetTimeout(VCard32 secs);
// I/O routines
// Send and Read return the number of bytes sent or recieved.
VInt Send(const char *buff, const VCard bufflen);
VInt Read(char *buff, const VCard bufflen);
VInt SendText(TCNString Text);
VInt WriteLn(TCNString Text) {return SendText(Text + AOL); }
VBool SendStream(TCNStream *Stream);
// SendExact and ReadExact attempt to send and recieve exactly
// the specified number of bytes.
VBool SendExact(const char *buff, const VCard bufflen);
VBool ReadExact(char *buff, const VCard bufflen);
////////////////////////////
// Internal structures
protected:
// The internal socket id
int sock;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -