c实现windows socket
2020-12-13 01:36
标签:style blog class c code java http://www.docin.com/p-111227070.html Java mina和c++ ace做socket长连接 测试报告: http://www.iteye.com/problems/44682 c++ RTMP server 做流媒体的 流媒体研究博客:http://www.cnblogs.com/haibindev http://www.rtmpd.com/ https://www.google.com.hk/#newwindow=1&q=rtmpc%2B%2B&safe=strict 用RTMP方式:通过NetConnection连接到FMS/Red5服务器,并实时播放服务器的FLV文件,这种方式可以任意选择视频播放点(SEEK()),并不象HTTP方式需要缓存完整个FLV文件到本地才可以任意选择播放点,其优点就是在本地缓存里是找不到这个FLV文件的。其优点就是FLV不会缓存在客户端,FLV的保密性好,其缺点就是消耗服务器资源,连接始终是实时的。 一句话,HTTP方式是本地播放,RTMP方式是服务器实时播放,因需而定。 c实现windows socket,搜素材,soscw.com c实现windows socket 标签:style blog class c code java 原文地址:http://www.cnblogs.com/as3lib/p/3744872.html服务端代码:
/*
* testSocketService.c
*
* Created on: 2012-8-16
* Author: 皓月繁星
*/
#include
#include
#define PORT 5150
#define MSGSIZE 1024
#pragma comment(lib, "ws2_32.lib")
int
main()
{
WSADATA wsaData;
SOCKET sListen;
SOCKET sClient;
SOCKADDR_IN local;
SOCKADDR_IN client;
char
szMessage[MSGSIZE];
int
ret;
int
iaddrSize =
sizeof
(SOCKADDR_IN);
WSAStartup(0x0202, &wsaData);
sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
local.sin_family = AF_INET;
local.sin_port = htons(PORT);
local.sin_addr.s_addr = htonl(INADDR_ANY);
bind(sListen, (
struct
sockaddr *) &local,
sizeof
(SOCKADDR_IN));
listen(sListen, 1);
sClient = accept(sListen, (
struct
sockaddr *) &client, &iaddrSize);
printf
(
"Accepted client:%s:%d\n"
, inet_ntoa(client.sin_addr),
ntohs(client.sin_port));
while
(TRUE) {
ret = recv(sClient, szMessage, MSGSIZE, 0);
szMessage[ret] =
‘\0‘
;
printf
(
"Received [%d bytes]: ‘%s‘\n"
, ret, szMessage);
}
return
0;
}
客户端代码
/*
* testSocketClient.c
*
* Created on: 2012-8-16
* Author: 皓月繁星
*/
#include