 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Frits JK Guest
|
Posted: Fri Jun 25, 2004 10:59 pm Post subject: problem sending chr(0) |
|
|
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 ;
}
//--------------------------------------------------------------------------
------------------
|
|
| Back to top |
|
 |
Howard Guest
|
Posted: Mon Jun 28, 2004 4:13 pm Post subject: Re: problem sending chr(0) |
|
|
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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|