Cooker
June 11th, 2007, 10:33 PM
Hi,
I write a server-client architecture application that is used to send live video to logined users. I create a class derived from CAsyncSocket:
class CUdpSendSocket : public CAsyncSocket
{
// Attributes
public:
bool m_bReadyToSend;
// Operations
public:
CUdpSendSocket();
virtual ~CUdpSendSocket();
virtual bool Send(const void *lpBuf, int nBufLen);
virtual void OnSend(int nErrorCode);
};
I create this as UPD socket:
CUdpSendSocket m_UdpSocket;
m_UdpSocket.Create(VIDEO_PORT, SOCK_DGRAM)
I use for-loop to send live images to all logined user
// IP_List stores the IP of logined user(s).
// IP_Count records the number of logined user(s)
for (index = 0 ; index < IP_Count ; ++index)
{
m_UdpSocket.m_strClientAddress = (char *)IP_List[index];
m_UdpSocket.Send(Stream, StreamLength);
}
If the number of user is greater than 1, I will get an error code "10035" and only the first logined user can receive image. So I solve this problem b this:
int index;
bool ret;
for (index = 0 ; index < IP_Count ; ++index)
{
m_UdpSocket.m_strClientAddress = (char *)IP_List[index];
ret = m_UdpSocket.Send(Stream, StreamLength);
if (ret == false)
--index;
}
But I don't know if this method is reasonable or not?
I write a server-client architecture application that is used to send live video to logined users. I create a class derived from CAsyncSocket:
class CUdpSendSocket : public CAsyncSocket
{
// Attributes
public:
bool m_bReadyToSend;
// Operations
public:
CUdpSendSocket();
virtual ~CUdpSendSocket();
virtual bool Send(const void *lpBuf, int nBufLen);
virtual void OnSend(int nErrorCode);
};
I create this as UPD socket:
CUdpSendSocket m_UdpSocket;
m_UdpSocket.Create(VIDEO_PORT, SOCK_DGRAM)
I use for-loop to send live images to all logined user
// IP_List stores the IP of logined user(s).
// IP_Count records the number of logined user(s)
for (index = 0 ; index < IP_Count ; ++index)
{
m_UdpSocket.m_strClientAddress = (char *)IP_List[index];
m_UdpSocket.Send(Stream, StreamLength);
}
If the number of user is greater than 1, I will get an error code "10035" and only the first logined user can receive image. So I solve this problem b this:
int index;
bool ret;
for (index = 0 ; index < IP_Count ; ++index)
{
m_UdpSocket.m_strClientAddress = (char *)IP_List[index];
ret = m_UdpSocket.Send(Stream, StreamLength);
if (ret == false)
--index;
}
But I don't know if this method is reasonable or not?