473,508 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ;
}

//--------------------------------------------------------------------------
------------------

Jul 22 '05 #1
1 1919

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


Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14484
by: coder_1024 | last post by:
I'm trying to send a packet of binary data to a UDP server. If I send a text string, it works fine. If I attempt to send binary data, it sends a UDP packet with 0 bytes of data (just the...
5
2608
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
1
2241
by: John | last post by:
Hi First of all apologies for posting so much code but this is rather involved and I am totally stumped. Basically I have a main form (Staff Batch SMS/E-Mail) which calls a function (SendSMS) in...
12
9616
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
19
11195
by: ... | last post by:
Hi I need to send a chr(255) to a serial port. When I send it, through comm.write (chr(255)) it sends a chr(63) ... in Hex, I write chr(&FF) and it actually sends chr(&3F) ... why does this...
3
3678
by: ... | last post by:
Hi I need to send a chr(255) to a serial port. When I send it, through comm.write (chr(255)) it sends a chr(63) ... in Hex, I write chr(&FF) and it actually sends chr(&3F) ... why does this...
1
4754
by: Mose | last post by:
Greetings! I am using Access '97 to track company orders. It's a pretty basic setup featuring a main table (tbl_SalesSlip) and a related table (tbl_ModelsSold). I would like to send an email that...
4
2557
by: charlie weaver | last post by:
I work for a large insurance company, and Im looking for a way to send emails with variable data to about 5,000 agents out in the field. (Not spam, I promise.) Id like to use Access to pull info...
2
1426
by: maharajakecil | last post by:
my GUI using VB6.0 had 2 textbox to allow user enter an integer that represent X and Y axes. there is any possible that i can send 2 data simultenously? do i need a delay? for your information, i...
12
13339
by: billelev | last post by:
This is probably a very easy question to answer: I have been outputting some text to a message box, similar to the following: strOutput = "---" & Chr(10) & Chr(10) strOutput = strOutput &...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.