SockStream: runtime error while streaming from UDP socket

Forum for software developers to discuss BCI2000 software development
Post Reply
BjornTJ
Posts: 2
Joined: 17 Jul 2015, 10:44

SockStream: runtime error while streaming from UDP socket

Post by BjornTJ » 17 Jul 2015, 10:59

I'm trying to use the BCI2000 to control a small robotic arm. I need to read the classifier from the BCI into a C++ program. So the ConnectorOutputAddress has been set to localhost:5051 and I'm using the example code from the App Connector page, which uses the SockStream class to read from a UDP socket. The code is as follows with the link to the wiki page:

Code: Select all

#include "stdafx.h"
#include <iostream>
#include "SockStream.h"

using namespace std;

int main( int argc, char** argv )
{

  const char* address = "localhost:5051";
  if( argc > 1 )
    address = argv[ 1 ];

  receiving_udpsocket socket( address );
  sockstream connection( socket );

  string line;

  // Print each line of BCI2000 input to stdout.
  while( getline( connection, line ) )
    //cout << line << endl;

  return 0;
}
http://www.bci2000.org/wiki/index.php/T ... _Connector

I have the BCI2000 running, but when I run this code I get the following error:

Code: Select all

'ReadOutput.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll'
'ReadOutput.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll'
'ReadOutput.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll'
'ReadOutput.exe': Loaded 'C:\Windows\SysWOW64\WSHTCPIP.DLL'
First-chance exception at 0x75a1c42d in ReadOutput.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0040f4f4..
The error occurs at getline( connector, line ), and can be traced back to the following function in the SockStream class which reads the size of the incoming stream:

Code: Select all

streamsize
streambuf::read( char* p, streamsize n )
{
  if( n < 1 )
    return 0;
  streamsize r = on_read( p, n );
  if( r < 0 )
    throw std::runtime_error( "Read failure" );
  m_read += r;
  return r;
}
Any help would be much appreciated.

pbrunner
Posts: 344
Joined: 17 Sep 2010, 12:43

Re: SockStream: runtime error while streaming from UDP socket

Post by pbrunner » 17 Jul 2015, 12:52

Bjorn,

to further isolate the problem, can you please summarize your setup (BCI2000 version (binary or svn revision#), Windows version and 32/64 bit, Compiler Version) and post a link to a minimal working example of the issue?

Regards, Peter

BjornTJ
Posts: 2
Joined: 17 Jul 2015, 10:44

Re: SockStream: runtime error while streaming from UDP socket

Post by BjornTJ » 20 Jul 2015, 12:37

As far as I remember I've been using the latest binary release, so I think that's 3.0.5, and I also downloaded the source as an archive which is where I found the sockstream class. I'm using Windows 7, 64-bit (could this be the problem?). The compiler is Visual C++ 2008. Is that enough information? Here's a link to the example code I'm using :

http://www.bci2000.org/wiki/index.php/T ... _Connector

I'm trying to control an external application reading from BCI2000 and running locally.

pbrunner
Posts: 344
Joined: 17 Sep 2010, 12:43

Re: SockStream: runtime error while streaming from UDP socket

Post by pbrunner » 20 Jul 2015, 17:59

Bjorn,

can you please try to download the trunk version from SVN (http://www.bci2000.org/svn/trunk) and see if the error persists there. Please note that for the trunk version, you need to use Visual Studio 2012 Express or Professional.

Regards, Peter

mrphunter
Posts: 4
Joined: 02 Jun 2015, 15:04

Re: SockStream: runtime error while streaming from UDP socket

Post by mrphunter » 23 Jul 2015, 08:11

Thanks Peter,

I actually just used the Sockstream class from the trunk version and this worked, as opposed to the other versions I had tried e.g from the archive. The problem seems to be solved. I'm not currently receiving anything from the port but this is an issue with my classifier...

pbrunner
Posts: 344
Joined: 17 Sep 2010, 12:43

Re: SockStream: runtime error while streaming from UDP socket

Post by pbrunner » 23 Jul 2015, 09:23

You are welcome and I am glad that the issue is resolved.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests