Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets 有谁能指导我或建议如何通过HTTP为实时媒体服务器流媒体制作客户端_Sockets_Live_H.264_Tcpclient_Rtsp - Fatal编程技术网

Sockets 有谁能指导我或建议如何通过HTTP为实时媒体服务器流媒体制作客户端

Sockets 有谁能指导我或建议如何通过HTTP为实时媒体服务器流媒体制作客户端,sockets,live,h.264,tcpclient,rtsp,Sockets,Live,H.264,Tcpclient,Rtsp,有谁能指导我或建议如何使客户端使用套接字通过HTTP进行实时媒体服务器流媒体,因为我尝试了很多,但都没有成功 #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #include <stdlib.h> #include <stdio.h> #include<conio.h> // Nee

有谁能指导我或建议如何使客户端使用套接字通过HTTP进行实时媒体服务器流媒体,因为我尝试了很多,但都没有成功

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include<conio.h>


// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")

//************All Declarations**********//
#define DEFAULT_BUFLEN 512000
#define DEFAULT_PORT "8000"

int __cdecl main(int argc, char **argv) 
{
    WSADATA wsaData;
    SOCKET ConnectSocket = INVALID_SOCKET;
    struct addrinfo *result = NULL,
        *ptr = NULL,
        hints;
    char *sendbuf = "this is a test";
    char recvbuf[DEFAULT_BUFLEN];
    int iResult;
    int recvbuflen = DEFAULT_BUFLEN;

    // Validate the parameters
    if (argc != 2) {
        printf("usage: %s server-name\n", argv[0]);
        getch();
        return 1;
    }

    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (iResult != 0) {
        printf("WSAStartup failed with error: %d\n", iResult);
        getch();
        return 1;
    }

    ZeroMemory( &hints, sizeof(hints) );
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    // Resolve the server address and port
    iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
    if ( iResult != 0 ) {
        printf("getaddrinfo failed with error: %d\n", iResult);
        WSACleanup();
        getch();
        return 1;
    }

    // Attempt to connect to an address until one succeeds
    for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) {

        // Create a SOCKET for connecting to server
        ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, 
            ptr->ai_protocol);
        if (ConnectSocket == INVALID_SOCKET) {
            printf("socket failed with error: %ld\n", WSAGetLastError());
            WSACleanup();
            getch();
            return 1;
        }

        // Connect to server.
        iResult = connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
        if (iResult == SOCKET_ERROR) {
            closesocket(ConnectSocket);
            ConnectSocket = INVALID_SOCKET;
            continue;
        }
        break;
    }

    freeaddrinfo(result);

    if (ConnectSocket == INVALID_SOCKET) {
        printf("Unable to connect to server!\n");
        WSACleanup();
        getch();
        return 1;
    }

    // Send an initial buffer
    /*iResult = send( ConnectSocket, sendbuf, (int)strlen(sendbuf), 0 );
    if (iResult == SOCKET_ERROR) {
        printf("send failed with error: %d\n", WSAGetLastError());
        closesocket(ConnectSocket);
        WSACleanup();
        getch();
        return 1;
    }*/

    printf("Bytes Sent: %ld\n", iResult);

    // shutdown the connection since no more data will be sent
    iResult = shutdown(ConnectSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        printf("shutdown failed with error: %d\n", WSAGetLastError());
        closesocket(ConnectSocket);
        WSACleanup();
        getch();
        return 1;
    }

    // Receive until the peer closes the connection
    do {

        iResult = recv(ConnectSocket, recvbuf, DEFAULT_BUFLEN, 0);
        if ( iResult > 0 )
            printf("Bytes received: %d\n", iResult);
        else if ( iResult == 0 )
            printf("Connection closed\n");
        else
            printf("recv failed with error: %d\n", WSAGetLastError());

    } while( iResult > 0 );


    // cleanup
    getch();
    closesocket(ConnectSocket);
    WSACleanup();


    return 0;
}
#定义WIN32_LEAN_和_MEAN
#包括
#包括
#包括
#包括
#包括
#包括
//需要链接到Ws2_32.lib、Mswsock.lib和Advapi32.lib
#pragma注释(lib,“Ws2_32.lib”)
#pragma注释(lib,“Mswsock.lib”)
#pragma注释(lib,“AdvApi32.lib”)
//************所有声明**********//
#定义默认值\u BUFLEN 512000
#定义默认_端口“8000”
内部cdecl主(内部argc,字符**argv)
{
WSADATA WSADATA;
SOCKET ConnectSocket=无效的_套接字;
struct addrinfo*result=NULL,
*ptr=NULL,
提示;
char*sendbuf=“这是一个测试”;
char recvbuf[默认值];
国际结果;
int recvbuflen=默认值;
//验证参数
如果(argc!=2){
printf(“用法:%s服务器名称\n”,argv[0]);
getch();
返回1;
}
//初始化Winsock
iResult=WSAStartup(MAKEWORD(2,2)和wsaData);
如果(iResult!=0){
printf(“WSAStartup失败,错误:%d\n”,iResult);
getch();
返回1;
}
零内存(&提示,sizeof(提示));
hits.ai_family=AF_unsec;
hits.ai_socktype=SOCK_流;
hits.ai_protocol=IPPROTO_TCP;
//解析服务器地址和端口
iResult=getaddrinfo(argv[1],默认端口、提示和结果);
如果(iResult!=0){
printf(“getaddrinfo失败,错误:%d\n”,iResult);
WSACleanup();
getch();
返回1;
}
//尝试连接到某个地址,直到连接成功
for(ptr=result;ptr!=NULL;ptr=ptr->ai_next){
//创建用于连接到服务器的套接字
连接插座=插座(ptr->ai_系列,ptr->ai_插座类型,
ptr->ai_协议);
if(ConnectSocket==无效的_套接字){
printf(“套接字失败,错误:%ld\n”,WSAGetLastError());
WSACleanup();
getch();
返回1;
}
//连接到服务器。
iResult=connect(ConnectSocket,ptr->ai_addr,(int)ptr->ai_addrlen);
if(iResult==SOCKET\u错误){
闭合插座(连接插座);
ConnectSocket=无效的_套接字;
继续;
}
打破
}
freeaddrinfo(结果);
if(ConnectSocket==无效的_套接字){
printf(“无法连接到服务器!\n”);
WSACleanup();
getch();
返回1;
}
//发送初始缓冲区
/*iResult=send(ConnectSocket,sendbuf,(int)strlen(sendbuf),0);
if(iResult==SOCKET\u错误){
printf(“发送失败,错误:%d\n”,WSAGetLastError());
闭合插座(连接插座);
WSACleanup();
getch();
返回1;
}*/
printf(“发送的字节数:%ld\n”,iResult);
//由于不再发送数据,请关闭连接
iResult=关机(ConnectSocket,SD_发送);
if(iResult==SOCKET\u错误){
printf(“关闭失败,错误:%d\n”,WSAGetLastError());
闭合插座(连接插座);
WSACleanup();
getch();
返回1;
}
//接收,直到对等方关闭连接
做{
iResult=recv(ConnectSocket,recvbuf,默认值为0);
如果(iResult>0)
printf(“收到的字节数:%d\n”,iResult);
else if(iResult==0)
printf(“连接关闭\n”);
其他的
printf(“recv失败,错误:%d\n”,WSAGetLastError());
}而(iResult>0);
//清理
getch();
闭合插座(连接插座);
WSACleanup();
返回0;
}

我尝试了上面的代码,它与我创建的服务器配合得很好。问题是,我正在通过http从live media server传输流文件,但当我尝试从客户端代码接收数据时,我可以通过特定url连接,但无法接收任何内容。

如果通过http传输,则必须先发送http请求(然后解析响应)


您没有收到任何内容,因为服务器正在等待请求

对您来说,最简单的解决方案是从开始使用客户机。基本上可以归结为实现整个RTSP堆栈以及通过TCP连接交错媒体。通过将“-T”作为命令行参数传递,您可以将openRTSP配置为通过TCP在RTSP上传输。然后,您可以基于openRTSP编写自己的应用程序,在该应用程序中,您可以根据需要处理传入的媒体样本

我建议您不要自己从套接字级别实现此功能。您需要实现RTSP、RTP、RTCP、RTSP over HTTP tunneling、SDP以及各种RTP有效负载格式,例如H.264。上面的套接字相关代码段没有开始接触表面

如果要查看协议交换的外观,请使用wireshark嗅探从openRTSP到RTSP服务器的通信量。您还可以在liveMedia上找到RTSP服务器