看新浪网上直播想到的,解决给1000分

talcon_hu 2003-03-05 08:24:36
新浪上的直播都是client端的网页去定时的刷新
我想可不可以由web服务器来通知网页去刷新
...全文
53 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
pi1ot 2003-03-17
  • 打赏
  • 举报
回复
不是说大话。
所以才不使用流方式而改用文字直播。
一个stream客户端要占用server多少带宽?sina直播这样的项目同时会有多少人去试图访问?

如果你做过大访问量的项目就会知道,选择技术不是以是否时髦为准的。
icelight 2003-03-17
  • 打赏
  • 举报
回复
to pi1ot(-=\Pilot/=-) 菜鸟:

你以为IE能接受UDP吗?客户端是浏览器时,播放流时最适合的就是用长连接了。

不懂就别说大话,虚心点。
icelight 2003-03-17
  • 打赏
  • 举报
回复
很高兴您有兴趣与我讨论这个问题。

选择技术是以项目需求为准的,只要项目的确需要大访问量,例如VOD,那么就要选择UDP,毕竟面对连接的TCP太耗资源了。

我不知道新浪的项目如何,所以我无法替他们选择文字直播还是流直播。我只是针对楼主的问题,作出应景的回答,与你说的"技术选择"好象有点不太相干,似乎是偏题了。

呵呵,不管怎样,我喜欢这种讨论,盼回信。
pi1ot 2003-03-15
  • 打赏
  • 举报
回复
在普通硬件条件下这种大规模海量访问的项目还采用什么不间断长连接纯粹是找死。
icelight 2003-03-06
  • 打赏
  • 举报
回复
talcon_hu() :

参考MyICQ的源码。原理与QQ一样,虽然代码质量差了点。
DoubleJiang 2003-03-06
  • 打赏
  • 举报
回复
up
88dd 2003-03-06
  • 打赏
  • 举报
回复
我发了,查收
talcon_hu 2003-03-06
  • 打赏
  • 举报
回复
to icelight(icelight):
大哥知道QQ用UDP是怎么实现的吗?
talcon_hu 2003-03-06
  • 打赏
  • 举报
回复
to 88dd:
My E-mail:Talcon_Hu@wistron.com.cn
88dd 2003-03-05
  • 打赏
  • 举报
回复
你的email是多少,我发给你。
88dd 2003-03-05
  • 打赏
  • 举报
回复
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#include <process.h>


SOCKET s = 0;
static char welcom[] = "Welcom<br>";
static char thanks[] = "thanks";

static char header2[] = "<html><head><title>hoverup</title>\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\n"
"</head><body>";

UINT __stdcall ListenThread(LPVOID LPPARAM)
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);

SOCKET socListen = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, WSA_FLAG_OVERLAPPED);
if (socListen == INVALID_SOCKET)
{
ATLTRACE(_T("Could not create listen socket %ld\n"),WSAGetLastError());
return false;
}

// Event for handling Network IO
HANDLE hEvent = WSACreateEvent();
if (hEvent == WSA_INVALID_EVENT)
{
ATLTRACE(_T("WSACreateEvent() error %ld\n"),WSAGetLastError());
closesocket(socListen);
return false;
}
int nRet;

nRet = WSAEventSelect(socListen,
hEvent,
FD_ACCEPT);

if (nRet == SOCKET_ERROR)
{
ATLTRACE(_T("WSAAsyncSelect() error %ld\n"),WSAGetLastError());
closesocket(socListen);
// return false;
}

SOCKADDR_IN saServer;

// Listen on our designated Port#
saServer.sin_port = htons( 81 );

// Fill in the rest of the address structure
saServer.sin_family = AF_INET;
saServer.sin_addr.s_addr = INADDR_ANY;

// bind our name to the socket
nRet = bind(socListen,
(LPSOCKADDR)&saServer,
sizeof(struct sockaddr));

if (nRet == SOCKET_ERROR)
{
ATLTRACE(_T("bind() error %ld\n"),WSAGetLastError());
closesocket(socListen);
// return false;
}

nRet = listen(socListen, 5);
if (nRet == SOCKET_ERROR)
{
ATLTRACE(_T("listen() error %ld\n"),WSAGetLastError());
closesocket(socListen);
// return false;
}

WSANETWORKEVENTS events;

DWORD dwRet;
int ret;

while( true )
{
Sleep( 500 );
if ( s )
{
ret = send( s, welcom, strlen( welcom ), 0 );
}
dwRet = WSAWaitForMultipleEvents(1,
&hEvent,
FALSE,
200,
FALSE);

if (dwRet == WSA_WAIT_TIMEOUT)
continue;

nRet = WSAEnumNetworkEvents(socListen,
hEvent,
&events);

if (nRet == SOCKET_ERROR)
{
ATLTRACE(_T("WSAEnumNetworkEvents error %ld\n"),WSAGetLastError());
break;
}

// Handle Network events //
// ACCEPT
if (events.lNetworkEvents & FD_ACCEPT)
{
if (events.iErrorCode[FD_ACCEPT_BIT] == 0)
{
SOCKADDR_IN SockAddr;
SOCKET clientSocket;

int nRet;
int nLen;

nLen = sizeof(SOCKADDR_IN);
clientSocket = accept(socListen,
(LPSOCKADDR)&SockAddr,
&nLen);

if (clientSocket == SOCKET_ERROR)
{
nRet = WSAGetLastError();
if (nRet != WSAEWOULDBLOCK)
{
//
// Just log the error and return
//
ATLTRACE(_T("accept() error\n"),WSAGetLastError());
}
}

const char chOpt = 1;
int nErr = setsockopt(clientSocket, IPPROTO_TCP, TCP_NODELAY, &chOpt, sizeof(char));
if (nErr == -1)
{
ATLTRACE(_T("setsockopt() error\n"),WSAGetLastError());
}
char buf[1024];
recv( clientSocket, buf, 1024, 0 );
if ( !strncmp( buf, "GET / HTTP", 10 ) )
{
int ret = send( clientSocket, header2, strlen( header2 ), 0 );
//return 0;
if ( s == 0 )
{
s = clientSocket;
//ret = send( s, welcom, strlen( welcom ), 0 );
}
else
{
ret = send( s, buf, sizeof( buf ), 0 );
ret = send( s, thanks, sizeof( thanks ), 0);
closesocket( clientSocket );
}
}
else
{
}
}
else
{
ATLTRACE(_T("Unknown network event error %ld\n"),WSAGetLastError());
break;
}
}
ResetEvent( hEvent );
}
WSACleanup();
return 0;
}

void StartServer()
{
UINT nThreadID;
HANDLE hListenThread = (HANDLE)_beginthreadex(NULL, // Security
0, // Stack size - use default
ListenThread, // Thread fn entry point
NULL,
0, // Init flag
&nThreadID); // Thread address
}
dishou 2003-03-05
  • 打赏
  • 举报
回复
up
congxiaojiuben 2003-03-05
  • 打赏
  • 举报
回复
http://www.21active.com/DataStorage/TechInfo/List.asp?TechType=1&TitleID=8
这是基于推技术的网址,你自己如果有时间的话去看看吧
congxiaojiuben 2003-03-05
  • 打赏
  • 举报
回复
推技术都不知道吗?看一下J2EE吧!它是B/S模式的
icelight 2003-03-05
  • 打赏
  • 举报
回复
自刷新页面?不会吧,新浪还在用这么落后的技术。

新浪不懂如何令服务器与IE之间的TCP连接不中断吗。

......

再笨点,用RM的流技术也行啊。自刷新页,嘿嘿,这也叫直播。



btw, 所谓推技术只是针对TCP连接而言。QQ用的是UDP,不面向连接,也就与"推"无关了。
talcon_hu 2003-03-05
  • 打赏
  • 举报
回复
to 88dd(巴迪):
(傻傻的问)什么是推技术?
能详细点吗?有源码就更好了!
解决给1000分,决不食言!
Bird1945 2003-03-05
  • 打赏
  • 举报
回复
up
and
mark
88dd 2003-03-05
  • 打赏
  • 举报
回复
可用推技术实现,就象聊天室,只让几个人发言,其它人进入没有发言权,就可得到网上直播的效果。

可以自己做一个HTTP Server,也可以用ISAPI。当客户连上服务器以后,服务器并不断开客户端连接,当有新数据时发往客户端就可以了。
9731boy 2003-03-05
  • 打赏
  • 举报
回复
UP
88dd 2003-03-05
  • 打赏
  • 举报
回复
好,我回家以后看还代码还在不在
加载更多回复(3)

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧