socket的send()方法的发送目的地址放在哪个参数里面?

socket的send()方法的发送目的地址放在哪个参数里面?... socket的send()方法的发送目的地址放在哪个参数里面? 展开
 我来答
木瓜亿客
2008-12-26 · 超过24用户采纳过TA的回答
知道答主
回答量:71
采纳率:0%
帮助的人:0
展开全部
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
denle
2008-12-26 · 超过23用户采纳过TA的回答
知道答主
回答量:172
采纳率:0%
帮助的人:75.3万
展开全部
This function sends data on a connected socket.

int send(
SOCKET s,
const char FAR* buf,
int len,
int flags
);
Parameters
s
[in] Descriptor identifying a connected socket.
buf
[in] Buffer containing the data to be transmitted.
len
[in] Length of the data in the buf parameter.
flags
[in] Indicator specifying the way in which the call is made.
Return Values
If no error occurs, this function returns the total number of bytes sent, which can be less than the number indicated by len for nonblocking sockets. If an error occurs, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError. The following table shows a list of possible error codes.

Error code Description
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set. Call setsockopt (Windows Sockets) with the SO_BROADCAST parameter to allow the use of the broadcast address.
WSAEINTR The socket was closed.
WSAEINPROGRESS A blocking Winsock call is in progress, or the service provider is still processing a callback function.
WSAEFAULT The buf parameter is not completely contained in a valid part of the user address space.
WSAENETRESET The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.
WSAENOBUFS No buffer space is available.
WSAENOTCONN The socket is not connected.
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP MSG_OOB was specified, but the socket is not stream style such as type SOCK_STREAM, out of band (OOB) data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.
WSAESHUTDOWN The socket has been shut down. It is not possible to send on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.
WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block.
WSAEMSGSIZE The socket is message-oriented, and the message is larger than the maximum supported by the underlying transport.
WSAEHOSTUNREACH The remote host cannot be reached from this host at this time.
WSAEINVAL The socket has not been bound with bind (Windows Sockets), an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.
WSAECONNABORTED The virtual circuit was terminated due to a time-out or other failure. The application should close the socket because it is no longer usable.
WSAECONNRESET The virtual circuit was reset by the remote side executing a hard or abortive close. For UDP sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a "Port Unreachable" ICMP packet. The application should close the socket because it is no longer usable.
WSAETIMEDOUT The connection has been dropped because of a network failure or because the system on the other end went down without notice.
WSAEPROTONOSUPPORT Protocol is not supported. For example, for raw sockets, if the IP_HDRINCL option set for the socket, and in the header the protocol field is set to TCP.

Remarks
This function is used to write outgoing data on a connected socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying provider, which can be obtained by using getsockopt (Windows Sockets) to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned and no data is transmitted.

The successful completion of a send call does not indicate that the data was successfully delivered.

If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode. On nonblocking stream-oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both client and server machines. The select or WSAEventSelect function can be used to determine when it is possible to send more data.

The flags parameter can be used to influence the behavior of the function beyond the options specified for the associated socket. The semantics of this function are determined by the socket options and the flags parameter. The following table shows the value used with the bitwise OR operator to construct the flags parameter.

Value Description
MSG_DONTROUTE Specifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag.

For more inforamtion about IrDA support in Windows CE, see Infrared Communications.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友3f1b5e1
2008-12-26 · TA获得超过537个赞
知道小有建树答主
回答量:505
采纳率:0%
帮助的人:640万
展开全部
send之前要先connect,目的地址是在connect的参数里的。

connect成功了才能send呀。呵呵
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式