自己写了一个socket向Live555的RTSP发送消息,为什么没有回应?麻烦大家帮看下
#include "stdafx.h"
#include <winsock2.h>
#include <winbase.h>
#include <iostream>
#pragma comment(lib, "ws2_32.lib")
#define PORT 554
void main(void)
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if(err != 0)
{
return;
}
if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{
WSACleanup();
return;
}
SOCKET sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr.S_un.S_addr = inet_addr("192.168.10.177");
int nConnect;
nConnect = connect(sock, (struct sockaddr FAR*)&server, sizeof(struct sockaddr_in));
if(nConnect == SOCKET_ERROR)
{
int erro = WSAGetLastError();
printf("connect fail !");
Sleep(3000);
closesocket(sock);
WSACleanup();
return;
}
char buffer2[1000] = "DESCRIBE rtsp://192.168.10.177/bipbop-gear1-all.ts RTSP/1.0"
"CSeq: 2"
"User-Agent: testRTSP (LIVE555 Streaming Media v2012.02.29)"
"Accept: application/sdp";
int nSend = 0;
nSend = send(sock, buffer2, sizeof(buffer2), 0);
if(nSend == SOCKET_ERROR)
{
printf("send fail !");
Sleep(3000);
return ;
}
printf("Send MSG success: %s",buffer2);
//Sleep(1000);
char buffer[1024];
int nAmount;
nAmount = recv(sock, buffer, sizeof(buffer), 0);
if(nAmount == SOCKET_ERROR)
{
closesocket(sock);
WSACleanup();
return ;
}
printf("Recv MSG success: %s",buffer);
//std::cout<<buffer<<std::endl;
Sleep(3000);
closesocket(sock);
WSACleanup();
}
[解决办法]
貌似应该先发OPTION请求才行。你可以看下live555服务器模块的源码,看了比较有概念。不过源码很复杂,需求不大的话,看个大概就好啦~
[解决办法]
客户端发送请求顺序OPTIONS——>DESCRIBE——>SETUP——>PLAY——>TEARDOWN