more TCP remote fixes

This commit is contained in:
Erwin Coumans 2020-03-20 21:12:45 -07:00
parent 1e3bc22483
commit 663c7ddc54
5 changed files with 35 additions and 14 deletions

View File

@ -113,6 +113,7 @@ SET(BulletRoboticsGUI_SRCS ${BulletRoboticsGUI_INCLUDES}
../../examples/SharedMemory/GraphicsServerExample.cpp
../../examples/SharedMemory/GraphicsClientExample.cpp
../../examples/SharedMemory/RemoteGUIHelper.cpp
../../examples/SharedMemory/RemoteGUIHelperTCP.cpp
../../examples/SharedMemory/GraphicsServerExample.h
../../examples/SharedMemory/GraphicsClientExample.h
../../examples/SharedMemory/RemoteGUIHelper.h

View File

@ -18,6 +18,7 @@ RobotSimulatorMain.cpp
../SharedMemory/GraphicsServerExample.cpp
../SharedMemory/GraphicsClientExample.cpp
../SharedMemory/RemoteGUIHelper.cpp
../SharedMemory/RemoteGUIHelperTCP.cpp
../SharedMemory/GraphicsServerExample.h
../SharedMemory/GraphicsClientExample.h
../SharedMemory/RemoteGUIHelper.h
@ -32,6 +33,7 @@ RobotSimulatorMain.cpp
IF(BUILD_CLSOCKET)
ADD_DEFINITIONS(-DBT_ENABLE_CLSOCKET)
ADD_DEFINITIONS(${OSDEF})
ENDIF(BUILD_CLSOCKET)

View File

@ -25,7 +25,7 @@
#include "GraphicsSharedMemoryCommands.h"
bool gVerboseNetworkMessagesServer = true;
bool gVerboseNetworkMessagesServer = false;
void MySerializeInt(unsigned int sz, unsigned char* output)
{
@ -52,7 +52,7 @@ void submitStatus(CActiveSocket* pClient, GraphicsSharedMemoryStatus& serverStat
if (gVerboseNetworkMessagesServer)
{
//printf("buffer.size = %d\n", buffer.size());
printf("buffer.size = %d\n", buffer.size());
printf("serverStatus packed size = %d\n", sz);
}
@ -63,7 +63,8 @@ void submitStatus(CActiveSocket* pClient, GraphicsSharedMemoryStatus& serverStat
packetData[i + curPos] = statBytes[i];
}
curPos += sizeof(GraphicsSharedMemoryStatus);
if (gVerboseNetworkMessagesServer)
printf("serverStatus.m_numDataStreamBytes=%d\n", serverStatus.m_numDataStreamBytes);
for (int i = 0; i < serverStatus.m_numDataStreamBytes; i++)
{
packetData[i + curPos] = buffer[i];
@ -157,7 +158,7 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
socket.Initialize();
socket.Listen("localhost", args->m_port);
socket.SetNonblocking();
int curNumErr = 0;
@ -166,6 +167,7 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
do
{
{
b3Clock::usleep(0);
}
@ -205,15 +207,18 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
//----------------------------------------------------------------------
// Receive request from the client.
//----------------------------------------------------------------------
while (cachedSharedParam != eTCPRequestTerminate)
{
//printf("try receive\n");
bool receivedData = false;
int maxLen = 4 + sizeof(GraphicsSharedMemoryCommand) + GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE;
if (pClient->Receive(maxLen))
{
//heuristic to detect disconnected clients
CSimpleSocket::CSocketError err = pClient->GetSocketError();
@ -225,14 +230,16 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
if (curNumErr > 100)
{
printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
break;
///printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
}
}
curNumErr = 0;
char* msg2 = (char*)pClient->GetData();
int numBytesRec2 = pClient->GetBytesReceived();
if (gVerboseNetworkMessagesServer)
printf("numBytesRec2=%d\n", numBytesRec2);
if (numBytesRec2 < 0)
{
numBytesRec2 = 0;
@ -334,7 +341,7 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
if (err != CSimpleSocket::SocketSuccess || !pClient->IsSocketValid())
{
curNumErr++;
printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
//printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
}
char* msg2 = (char*)pClient->GetData();
int numBytesRec2 = pClient->GetBytesReceived();
@ -473,10 +480,18 @@ void TCPThreadFunc(void* userPtr, void* lsMemory)
}
if (hasStatus)
{
if (gVerboseNetworkMessagesServer)
printf("pre-submit Status\n");
submitStatus(pClient, serverStatus, buffer);
if (gVerboseNetworkMessagesServer)
printf("post-submit Status\n");
}
if (gVerboseNetworkMessagesServer)
printf("pre clearing bytesReceived\n");
bytesReceived.clear();
if (gVerboseNetworkMessagesServer)
printf("post clearing bytesReceived\n");
}
else
{

View File

@ -22,7 +22,7 @@ static unsigned int b3DeserializeInt3(const unsigned char* input)
unsigned int tmp = (input[3] << 24) + (input[2] << 16) + (input[1] << 8) + input[0];
return tmp;
}
static bool gVerboseNetworkMessagesClient3 = true;
static bool gVerboseNetworkMessagesClient3 = false;
const char* cmd2txt[]=
{
@ -197,16 +197,17 @@ struct RemoteGUIHelperTCPInternalData
return true;
m_tcpSocket.Initialize();
m_isConnected = m_tcpSocket.Open(m_hostName.c_str(), m_port);
if (m_isConnected)
{
m_tcpSocket.SetSendTimeout(m_timeOutInSeconds, 0);
m_tcpSocket.SetReceiveTimeout(m_timeOutInSeconds, 0);
m_tcpSocket.SetNonblocking();
}
int key = GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER;
m_tcpSocket.Send((uint8*)&key, 4);
return m_isConnected;
}

View File

@ -314,6 +314,8 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingEx
return (b3PhysicsClientHandle)cl;
}
#ifdef BT_ENABLE_CLSOCKET
#include "RemoteGUIHelperTCP.h"
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnectTCP(const char* hostName, int port)
@ -566,4 +568,4 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessGraphicsServerAndConnectMai
return (b3PhysicsClientHandle)cl;
}
#endif