一个服务端和若干个客户端
当服务端和若干客户端建立连接后
服务端如何给特定的客户端发送消息?自己的想法是再建立连接时 给每个客户端添加标识大家都是怎么解决的??
当服务端和若干客户端建立连接后
服务端如何给特定的客户端发送消息?自己的想法是再建立连接时 给每个客户端添加标识大家都是怎么解决的??
解决方案 »
- CListBox::AddString(..)的奇怪问题:显示的时候每个字符串是双份
- 问个菜问题,有关OnPaint
- 谁帮忙设计下怎么用MFC设计一个数据库程序,讲解下实现步骤,我第一次做这东西
- 请教一个MDI程序中的问题~~~~
- 关于屏幕保护程序的问题
- 各位,谁知道“英化”VC++创天中文版的东东?这年月,英文版不好找啊...
- 串口传送图像文件求!
- 关于怎么得到W2000下所有运行的进程的信息??!!! Online;;
- 如何将 BSTR pVal 赋给:unsigned char *pw;如何将:unsigned char digest[16]赋给 BSTR *pOutVal
- _T() 和 TEXT() 有什么区别和联系?
- 请问如何将 Visual Studio6安装好后的英文版变为中文版,通安装Visual Studio Service Pack 6简体中文版可以转变成中文版吗?
- 急问!socket的server端和client端的常用模型是什么?
服务器接收连接(accept)以后,
会有一个socket套接字还有客户端的IP及端口信息,
这些足以标识一个socket了。
socke[i]=accept();
我如何得到socket[i]的端口和ip那?
accept
The Windows Sockets accept function accepts an incoming connection attempt on a socket.SOCKET accept (
SOCKET s,
struct sockaddr FAR* addr,
int FAR* addrlen
);
Parameters
s
[in] A descriptor identifying a socket that has been placed in a listening state with the listen function. The connection will actually be made with the socket that is returned by accept.
addr
[out] An optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family established when the socket was created.
addrlen
[out] An optional pointer to an integer that contains the length of the address addr. struct sockaddr_in{
short sin_family;
unsigned short sin_port; // 客户端端口
struct in_addr sin_addr; // 客户端地址
char sin_zero[8];
};【Return Values】
If no error occurs, accept returns a value of type SOCKET that is a descriptor for the new socket. This returned value is a handle for the socket on which the actual connection will be made.Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError.The integer referred to by addrlen initially contains the amount of space pointed to by addr. On return it will contain the actual length in bytes of the address returned.