getsockoptsocket的send()方法的发送目的地址放在哪个参数里面?
getsockopt 时间:2021-08-02 阅读:(
)
求VC++中的头文件Afxcsock.h
直接给你吧,保存为Afxsock.h 不是Afxcsock.h 路径是 在VC98MFCINCLUDE
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#ifndef __AFXSOCK_H__
#define __AFXSOCK_H__
#ifdef _AFX_NO_SOCKET_SUPPORT
#error Windows Sockets classes not supported in this library variant.
#endif
#ifndef __AFXWIN_H__
#include
#endif
#ifndef _WINSOCKAPI_
#include
#endif
#ifdef _AFX_MINREBUILD
#ponent(minrebuild, off)
#endif
#ifndef _AFX_FULLTYPEINFO
#ponent(mintypeinfo, on)
#endif
#ifndef _AFX_NOFORCE_LIBS
/////////////////////////////////////////////////////////////////////////////
// Win32 libraries
#ifdef _AFXDLL
#if defined(_DEBUG) && !defined(_AFX_MONOLITHIC)
#ifndef _UNICODE
#ment(lib, "42d.lib")
#else
#ment(lib, "42ud.lib")
#endif
#endif
#endif
#ment(lib, "wsock32.lib")
#endif //!_AFX_NOFORCE_LIBS
/////////////////////////////////////////////////////////////////////////////
#ifdef _AFX_PACKING
#pragma pack(push, _AFX_PACKING)
#endif
/////////////////////////////////////////////////////////////////////////////
// AFXSOCK - MFC support for Windows Sockets
// Classes declared in this file
// CObject
class CAsyncSocket; // Async Socket implementation and
// base class for Synchronous Socket
class CSocket; // Synchronous Socket
// CFile
class CSocketFile; // Used with CSocket and CArchive for
// streaming objects on sockets.
/////////////////////////////////////////////////////////////////////////////
// AFXDLL support
#undef AFX_DATA
#define AFX_DATA AFX_NET_DATA
/////////////////////////////////////////////////////////////////////////////
// CSocketWnd -- internal use only
// Implementation for sockets notification callbacks.
// Future versions of MFC may or may not include this exact class.
class CSocketWnd : public CWnd
{
// Construction
public:
CSocketWnd();
protected:
//{{AFX_MSG(CSocketWnd)
LRESULT OnSocketNotify(WPARAM wParam, LPARAM lParam);
LRESULT OnSocketDead(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// CAsyncSocket
class CAsyncSocket : public CObject
{
DECLARE_DYNAMIC(CAsyncSocket);
private:
CAsyncSocket(const CAsyncSocket& rSrc); // no implementation
void operator=(const CAsyncSocket& rSrc); // no implementation
// Construction
public:
CAsyncSocket();
BOOL Create(UINT nSocketPort = 0, int nSocketType=SOCK_STREAM,
long lEvent = FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,
LPCTSTR lpszSocketAddress = NULL);
// Attributes
public:
SOCKET m_hSocket;
operator SOCKET() const;
BOOL Attach(SOCKET hSocket, long lEvent =
FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
SOCKET Detach();
BOOL GetPeerName(CString& rPeerAddress, UINT& rPeerPort);
BOOL GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen);
BOOL GetSockName(CString& rSocketAddress, UINT& rSocketPort);
BOOL GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen);
BOOL SetSockOpt(int nOptionName, const void* lpOptionValue,
int nOptionLen, int nLevel = SOL_SOCKET);
BOOL GetSockOpt(int nOptionName, void* lpOptionValue,
int* lpOptionLen, int nLevel = SOL_SOCKET);
static CAsyncSocket* PASCAL FromHandle(SOCKET hSocket);
static int PASCAL GetLastError();
// Operations
public:
virtual BOOL ept(CAsyncSocket& rConnectedSocket,
SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL);
BOOL Bind(UINT nSocketPort, LPCTSTR lpszSocketAddress = NULL);
BOOL Bind (const SOCKADDR* lpSockAddr, int nSockAddrLen);
virtual void Close();
BOOL Connect(LPCTSTR lpszHostAddress, UINT nHostPort);
BOOL Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen);
BOOL IOCtl(long lCommand, DWORD* lpArgument);
BOOL Listen(int nConnectionBacklog=5);
virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
int ReceiveFrom(void* lpBuf, int nBufLen,
CString& rSocketAddress, UINT& rSocketPort, int nFlags = 0);
int ReceiveFrom(void* lpBuf, int nBufLen,
SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags = 0);
enum { receives = 0, sends = 1, both = 2 };
BOOL ShutDown(int nHow = sends);
virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0);
int SendTo(const void* lpBuf, int nBufLen,
UINT nHostPort, LPCTSTR lpszHostAddress = NULL, int nFlags = 0);
int SendTo(const void* lpBuf, int nBufLen,
const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags = 0);
BOOL AsyncSelect(long lEvent =
FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
// Overridable callbacks
protected:
virtual void OnReceive(int nErrorCode);
virtual void OnSend(int nErrorCode);
virtual void OnOutOfBandData(int nErrorCode);
virtual void ept(int nErrorCode);
virtual void OnConnect(int nErrorCode);
virtual void OnClose(int nErrorCode);
// Implementation
public:
virtual ~CAsyncSocket();
static CAsyncSocket* PASCAL LookupHandle(SOCKET hSocket, BOOL bDead = FALSE);
static void PASCAL AttachHandle(SOCKET hSocket, CAsyncSocket* pSocket, BOOL bDead = FALSE);
static void PASCAL DetachHandle(SOCKET hSocket, BOOL bDead = FALSE);
static void PASCAL KillSocket(SOCKET hSocket, CAsyncSocket* pSocket);
static void PASCAL DoCallBack(WPARAM wParam, LPARAM lParam);
BOOL Socket(int nSocketType=SOCK_STREAM, long lEvent =
FD_READ | FD_WRITE | FD_OOB | FD_ACCEPT | FD_CONNECT | FD_CLOSE,
int nProtocolType = 0, int nAddressFormat = PF_INET);
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
friend class CSocketWnd;
virtual BOOL ConnectHelper(const SOCKADDR* lpSockAddr, int nSockAddrLen);
virtual int ReceiveFromHelper(void* lpBuf, int nBufLen,
SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags);
virtual int SendToHelper(const void* lpBuf, int nBufLen,
const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags);
};
/////////////////////////////////////////////////////////////////////////////
// CSocket
class CSocket : public CAsyncSocket
{
DECLARE_DYNAMIC(CSocket);
private:
CSocket(const CSocket& rSrc); // no implementation
void operator=(const CSocket& rSrc); // no implementation
// Construction
public:
CSocket();
BOOL Create(UINT nSocketPort = 0, int nSocketType=SOCK_STREAM,
LPCTSTR lpszSocketAddress = NULL);
// Attributes
public:
BOOL IsBlocking();
static CSocket* PASCAL FromHandle(SOCKET hSocket);
BOOL Attach(SOCKET hSocket);
// Operations
public:
void CancelBlockingCall();
// Overridable callbacks
protected:
virtual BOOL OnMessagePending();
// Implementation
public:
int m_nTimeOut;
virtual ~CSocket();
static int PASCAL ProcessAuxQueue();
virtual BOOL ept(CAsyncSocket& rConnectedSocket,
SOCKADDR* lpSockAddr = NULL, int* lpSockAddrLen = NULL);
virtual void Close();
virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0);
int SendChunk(const void* lpBuf, int nBufLen, int nFlags);
protected:
friend class CSocketWnd;
BOOL* m_pbBlocking;
int m_nConnectError;
virtual BOOL ConnectHelper(const SOCKADDR* lpSockAddr, int nSockAddrLen);
virtual int ReceiveFromHelper(void* lpBuf, int nBufLen,
SOCKADDR* lpSockAddr, int* lpSockAddrLen, int nFlags);
virtual int SendToHelper(const void* lpBuf, int nBufLen,
const SOCKADDR* lpSockAddr, int nSockAddrLen, int nFlags);
static void PASCAL AuxQueueAdd(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL PumpMessages(UINT Flag);
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
/////////////////////////////////////////////////////////////////////////////
// CSocketFile
class CSocketFile : public CFile
{
DECLARE_DYNAMIC(CSocketFile)
public:
//Constructors
CSocketFile(CSocket* pSocket, BOOL bArchiveCompatible = TRUE);
// Implementation
public:
CSocket* m_pSocket;
BOOL m_bArchiveCompatible;
virtual ~CSocketFile();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
virtual UINT Read(void* lpBuf, UINT nCount);
virtual void Write(const void* lpBuf, UINT nCount);
virtual void Close();
// Unsupported APIs
virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError = NULL);
virtual CFile* Duplicate() const;
virtual DWORD GetPosition() const;
virtual LONG Seek(LONG lOff, UINT nFrom);
virtual void SetLength(DWORD dwNewLen);
virtual DWORD GetLength() const;
virtual void LockRange(DWORD dwPos, DWORD dwCount);
virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
virtual void Flush();
virtual void Abort();
};
/////////////////////////////////////////////////////////////////////////////
// Global functions
BOOL AFXAPI AfxSocketInit(WSADATA* lpwsaData = NULL);
void AFXAPI AfxSocketTerm();
/////////////////////////////////////////////////////////////////////////////
// Inline function declarations
#ifdef _AFX_PACKING
#pragma pack(pop)
#endif
#ifdef _AFX_ENABLE_INLINES
#define _AFXSOCK_INLINE AFX_INLINE
#include
#undef _AFXSOCK_INLINE
#endif
#undef AFX_DATA
#define AFX_DATA
#ifdef _AFX_MINREBUILD
#ponent(minrebuild, on)
#endif
#ifndef _AFX_FULLTYPEINFO
#ponent(mintypeinfo, off)
#endif
#endif // __AFXSOCK_H__
/////////////////////////////////////////////////////////////////////////////C语言 send()函数理解
使用函数getsockopt获得发送缓冲区的长度。
用法如下:
int sockfd;
int val;
int len;
sockfd = socket (AF_INET, SOCK_STREAM, 0);
len = sizeof (val);
getsockopt( sockfd, SOL_SOCKET, SO_SNDBUF, &val, &len);
printf ("sndbuf len=%d
", val);
在32位linux系统上发送缓冲区为16K ,可以使用setsockopt()修改,会影响网络性能想用getsockopt取得当前socket的状态,但是第三个参数怎么设置啊。
选项 类型 意义
SO_ACCEPTCONN BOOL 套接口正在用listen()监听。
SO_BROADCAST BOOL 套接口设置为传送广播信息。
SO_DEBUG BOOL 允许调试。
SO_DONTLINER BOOL 若为真,则SO_LINGER选项被禁止。
SO_DONTROUTE BOOL 禁止选径。
SO_ERROR int 获取错误状态并清除。
SO_KEEPALIVE BOOL 发送“保持活动”信息。
SO_LINGER struct linger FAR* 返回当前各linger选项。
SO_OOBINLINE BOOL 在普通数据流中接收带外数据。
SO_RCVBUF int 接收缓冲区大小。
SO_REUSEADDR BOOL 套接口能和一个已在使用中的地址捆绑。
SO_SNDBUF int 发送缓冲区大小。
SO_TYPE int 套接口类型(如SOCK_STREAM)。
TCP_NODELAY BOOL 禁止发送合并的Nagle算法。
这些就足够了,自己选吧socket的send()方法的发送目的地址放在哪个参数里面?
send是TCP通信的发送方法,在send之前保证建立了socket通信连接,socket中记录了与之连接的对方的地址,所以可以说是第一个参数SOCKET记录了要发往的地址;注:TCP套接字只能进行一对一的通信,所以不需要地址再来进行目的地的标识,套接字就可以确定要发往的方向;
SOCKET Sock;
Sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
connect(Sock,。
。
。
。
。
。
。
);
char *buf;
send(Sock,buf,strlen(buf),0);
其中就是Sock记录的你要发往的目的地;
只有UDP通信才要写入对方地址,UDP套接可以进行多对多的通信,所以在发送的时候要写入对方地址;
UDP调用sendto()方法;可以查看MSDN
傲游主机怎么样?傲游主机是一家成立于2010年的老牌国外VPS服务商,在澳大利亚及美国均注册公司,是由在澳洲留学的害羞哥、主机论坛知名版主组长等大佬创建,拥有多家海外直连线路机房资源,提供基于VPS主机和独立服务器租用等,其中VPS基于KVM或者XEN架构,可选机房包括中国香港、美国洛杉矶、韩国、日本、德国、荷兰等,均为CN2或者国内直连优秀线路。傲游主机提供8折优惠码:haixiuge,适用于全...
特网云官網特网云服务器在硬件级别上实现云主机之间的完全隔离;采用高端服务器进行部署,同时采用集中的管理与监控,确保业务稳定可靠,搭建纯SSD架构的高性能企业级云服务器,同时采用Intel Haswell CPU、高频DDR4内存、高速Sas3 SSD闪存作为底层硬件配置,分钟级响应速度,特网云采用自带硬防节点,部分节点享免费20G防御,可实现300G防御峰值,有效防御DDoS、CC等恶意攻击,保障...
v5net当前对香港和美国机房的走优质BGP+CN2网络的云服务器进行7折终身优惠促销,每个客户进线使用优惠码一次,额外有不限使用次数的终身9折优惠一枚!V5.NET Server提供的都是高端网络线路的机器,特别优化接驳全世界骨干网络,适合远程办公、跨境贸易、网站建设等用途。 官方网站:https://v5.net/cloud.html 7折优惠码:new,仅限新客户,每人仅限使用一次 9...
getsockopt为你推荐
upper消毒柜上的upper是什么意思bft有懂BFT的行家吗?请简单的介绍下removechild解释下这条语句this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);百度云论坛请问论坛有网盘么?apple以旧换新苹果以旧换新吗活动 可以换钱吗,还是只能折抵新手机横幅广告促销横幅怎么写系统登录界面谁知道XP系统的登录界面。和启动界面怎么更改的 急碰撞球如何在flash中制作小球碰撞动画?vrrp配置这段H3C路由器上的配置什么意思?手机壳生产厂家手机保护套保护壳厂家
网站空间申请 虚拟主机评测网 汉邦高科域名注册 播放vps上的视频 美国主机排名 java主机 tier mediafire下载 2017年黑色星期五 网站实时监控 华为4核 免费活动 电信主机 smtp虚拟服务器 独享主机 上海电信测速 帽子云排名 域名转入 开心online 香港ip 更多