Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i want to save and decode a video slice from a live video stream sent from my raspberry pi to windows PC via TCP/IP using raspivid and netcat.


i run my pi code 1st. i get the video displayed on my pi screen.
but when i run the client, i get an error "Connection to server failed"
I am confused in how do acheive the same.

when i use the command
nc -l 5001 i get a connection from the server to the client. but when i use the netcat command on the raspberry pi, then i am getting a issue

What I have tried:

on the pi side i am using a a standard netcat code:

raspivid -t 0 -o - | nc 172.16.26.32 5001 (my windows pc address and the port number)

on the Windows side, i have used

C++
int main(int argc, char* argv[])
{
        WSADATA wsaData = {0};
	WORD wVer = MAKEWORD(2,2);
         int nRet = WSAStartup( wVer, &wsaData );

        WORD WSAEvent = 0;
	WORD WSAErr = 0;
	SOCKET hServer = {0};
 
    hServer = socket( AF_INET, SOCK_STREAM, IPPROTO_IP );
    sockaddr_in saServer = {0};
    saServer.sin_family = PF_INET;
    saServer.sin_port = htons( 5001 );
    saServer.sin_addr.s_addr = inet_addr( "172.16.26.92" ); //address of raspberry pi

    nRet = connect( hServer, (sockaddr*)&saServer, sizeof( sockaddr ) );
    if( nRet == SOCKET_ERROR ) 
	{
		cout << "Connection to server failed" << endl;
         }	
	else
               do
	       {
		        stat = recv(socket, (char*)&imsize, sizeof(imsize),0);
	       }while(stat<2040); //the reason i used a sat value as finite is because i am reading a slice of data from a live video stream.
Posted
Updated 12-May-16 12:35pm

1 solution

C#
raspivid -t 0 -o - | nc 172.16.26.32 5001 (my windows pc address and the port number)

Seems like you're running this as a client...


C++
nRet = connect( hServer, (sockaddr*)&saServer, sizeof( sockaddr ) );
if( nRet == SOCKET_ERROR )
{
    cout << "Connection to server failed" << endl;
     }

Seems like you're running this as a client...


You have to make one side the server and the other the client, otherwise you have two clients and no servers.
 
Share this answer
 
Comments
violence666 17-May-16 3:57am    
Thank you so much. I made the raspberry pi as the server by simply
<pre lang="c++">raspivid -t 0 -o - | nc -l 5001 </pre>
where "-l" listens to the port 5001 and sends data as soon as it senses a connection.

On the client side, i replaced

<pre lang="c++">do
{
stat = recv(socket, (char*)&imsize, sizeof(imsize),0);
}while(stat<2040);</pre>

with
<pre lang="c++">do
{
stat = recv(socket, (char*)&imsize, sizeof(imsize),0);
}while(stat<0);</pre>

when stat is equal to 0, then the client infinitely receives the server data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900