problem sending chr(0)

F

Frits JK

Hallo, I have a function in a DLL which is te interface between a xBase
program and a PLC.
most things work fine exept when I send or receive command-string contains a
character 0.

knows any body a solution for this problem.

Frits Janse Kok

//--------------- begin of
code ---------------------------------------------------------------------
extern "C" int PASCAL EXPORT ReadMidi( char const *szIPAddr , char
*Opdracht , char * Antwoord , int *lengte )

{

#define IPPORT_MIDIXP 6768
#define nBuf 255
static SOCKET sock ;
static struct sockaddr_in sa ;
WSADATA WSAData ;
int status;

//-------------- versienummer instellen -------------
if ( WSAStartup( 0x202, &WSAData) != 0 )
{
WSACleanup();
return -1 ;
}

//----------- Call "socket" ( internetprocol, Sock protocol, UDP-IP )
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) ;
if (sock < 0)
{
WSACleanup () ;
return -2 ;
}

// ------------- Call "connect" with IP address and time-server port
sa.sin_family = AF_INET ;
sa.sin_port = htons (IPPORT_MIDIXP) ;
sa.sin_addr.S_un.S_addr = inet_addr (szIPAddr) ;

if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) == SOCKET_ERROR )

{ closesocket (sock) ;
WSACleanup () ;
return -3 ;
}


if ( send(sock, (char*)Opdracht , *lengte , 0) == SOCKET_ERROR )

{ closesocket (sock) ;
WSACleanup();
return -4;
}

status = recv( sock , Antwoord, nBuf , 0 ) ;
closesocket(sock);
WSACleanup();
if (status < 0 ) return -5;
if (status == 0 ) return -6;

*lengte = status;
return 0 ;
}

//--------------------------------------------------------------------------
------------------
 
H

Howard

I don't know how the socket send and recieve function are declared (and
socket programming is off-topic here, check a microsoft newsgroup or
someplace else that discusses the specific platform or technology). But my
guess would be that those are designed to pass text, not binary. You should
read the appropriate manual for the socket functions to see what they
accept. I would suspect that the parameters are declared with names like
LPSZBUF or something like that. The "SZ" indicates a null-terminated
string, which means that a zero will signal the end of the string. THat's a
clear indication that text is expected, not binary. Sometimes, I know that
you can pass binary by preceding the value with an "escape" character. In
HTTP, it's a %, followed by the hex value, I think, as in "%20" for a space.
You'll have to check your documentation for how to pass binary in a socket
send or receive call.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top