Error sending data via Socket

Hello,

I'm working on a Kinect Application wich need to send the Real Coordenates of the face to another program, Matlab, now i've a Console application acting as a Client (who receive the data).
I test the code apart from the Kinect program and works fine (the message is sent) but when I implement it to the Kinect code and receive in matlab the connection works but the data doesn't show in Matlab.

Any ideas of what I have to change in code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

//KinectFaceTrackingFunction
void SingleFace::FTHelperCallingBack(PVOID pVoid)
{
    SingleFace* pApp = reinterpret_cast<SingleFace*>(pVoid);
    if (pApp)
    {
        IFTResult* pResult = pApp->m_FTHelper.GetResult();
        if (pResult && SUCCEEDED(pResult->GetStatus()))
        {
			char *sendbuf = new char[buffsize];
			long SUCCESFUL;
			WSAData WinSockData;
			WORD DLLVERSION;
			DLLVERSION = MAKEWORD(2, 1);
			SUCCESFUL = WSAStartup(DLLVERSION, &WinSockData);
			SOCKET sock_CONNECTION;
			sock_CONNECTION = socket(AF_INET, SOCK_STREAM, NULL);
            
			FLOAT* pAU = NULL;
            UINT numAU;
            pResult->GetAUCoefficients(&pAU, &numAU);
            pApp->m_eggavatar.SetCandideAU(pAU, numAU);
            FLOAT scale;
            FLOAT rotationXYZ[3];
            FLOAT translationXYZ[3];
			
            pResult->Get3DPose(&scale, rotationXYZ, translationXYZ);
            pApp->m_eggavatar.SetTranslations(translationXYZ[0], translationXYZ[1], translationXYZ[2]);
            pApp->m_eggavatar.SetRotations(rotationXYZ[0], rotationXYZ[1], rotationXYZ[2]);

			// MOSTRANDO RESULTADOS EN LA VENTANDA OUTPUT
			std::string resultados = "T = [" + to_string(translationXYZ[0]) + "," + to_string(translationXYZ[1]) + "," + to_string(translationXYZ[2]) + ", ], R=[" + to_string(rotationXYZ[0]) + "," + to_string(rotationXYZ[0]) + "," + to_string(rotationXYZ[1]) + "," + to_string(rotationXYZ[2]) + "], sc=" + to_string(scale) + "/n";
			std::wstring stemp = s2ws(resultados);
			LPCWSTR results = stemp.c_str();
			OutputDebugStringW(results);
			
			/*Matrix to calculate the real coordenates
			A1 = 98.1987    4.8642
				 -6.3882   79.6357
				  9.9648   20.0521*/
			 
			double xr = 98.1987*translationXYZ[0] - 6.3882*translationXYZ[2]  + 9.9648;
			double yr =  4.8642*translationXYZ[0] + 79.6357*translationXYZ[2] + 20.0521;
			
			
			
			sprintf(sendbuf, "%+07.2f %+07.2f\n", xr, yr);
			send(sock_CONNECTION, sendbuf, 17, NULL);

			cout << "Sent: (" << xr << "," << yr << ")\n";
			
		}
	}	
}



// Program's main entry point
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
{
	AllocConsole();
	freopen("CONIN$", "r", stdin);
	freopen("CONOUT$", "w", stdout);
	freopen("CONOUT$", "w", stderr);
	
	
	//SERVER
	long SUCCESFUL;
	WSAData WinSockData;
	WORD DLLVERSION;
	DLLVERSION = MAKEWORD(2, 1);
	SUCCESFUL = WSAStartup(DLLVERSION, &WinSockData);
	SOCKADDR_IN ADDRESS;
	int AddressSize = sizeof(ADDRESS);

	SOCKET sock_LISTEN;
	SOCKET sock_CONNECTION;
	sock_CONNECTION = socket(AF_INET, SOCK_STREAM, NULL);
	ADDRESS.sin_addr.s_addr = inet_addr("127.0.0.1");
	ADDRESS.sin_family = AF_INET;
	ADDRESS.sin_port = htons(444);
	sock_LISTEN = socket(AF_INET, SOCK_STREAM, NULL);
	bind(sock_LISTEN, (SOCKADDR*)&ADDRESS, sizeof(ADDRESS));
	listen(sock_LISTEN, SOMAXCONN);
	for (;;)
	{
		cout << "\n\tSERVER: Waiting for incomming connetion...";
		if (sock_CONNECTION = accept(sock_LISTEN, (SOCKADDR*)&ADDRESS, &AddressSize));
		{
			cout << " \n\tA connection was found! " << endl;
			UNREFERENCED_PARAMETER(hPrevInstance);
			SingleFace app;
			HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
			return app.Run(hInstance, lpCmdLine, nCmdShow);
		}
	}
 }


//Matlab Code
t = tcpip('127.0.0.1',444,'NetworkRole', 'client');
fopen(t);
while (1)
 % Sabemos que el mensaje tiene 17 bytes (o los que hayas enviado)
    d=fread(t,17);
 % Los 16 primeros son los bytes útiles, el 17 era el fin de cadena
 % De momento, se muestran por pantalla, como caracteres,
 % sólo para ver que llegan bien.
    for i=1:16
        fprintf(1,'%c',d(i));
    end;
xr = str2double(d(1:7));
yr = str2double(d(9:15));
plot(xr, yr);
end;
Last edited on
Topic archived. No new replies allowed.