473,569 Members | 2,453 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_u n.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(soc k);
WSACleanup();
if (status < 0 ) return -5;
if (status == 0 ) return -6;

*lengte = status;
return 0 ;
}

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

Jul 22 '05 #1
1 1926

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
14497
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 headers). I can see this because I'm running Ethereal and watching the packets. I'm defining the packets as shown below: $text_msg = "Hello,...
5
2613
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 depending on member expiration dates. When the form is submitted, the code loops through the form contents and sends an email to those members that...
1
2247
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 a module with in turn calls a form (frmInet) which contains an ms internet control (Inet1). Problem is that once the function Send SMS returns and...
12
9622
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(" & Chr(34) & PopUpWindowTitle & Chr(34) & ", " & Chr(34) & CurrentEventDetails & ")" strTemp += "<BR><A HREF='#' onClick='" & PopupLink & "'>" & EventName &...
19
11208
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 happen, and how can I send it right ? I'm using vb.net 2005 express with framework 2.0 Thanks for an answear ...
3
3680
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 happen, and how can I send it right ? I'm using vb.net 2005 express with framework 2.0 Thanks for an answear ...
1
4767
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 contains information from both tables, but am unsure how to go about it. The data is normalized. A sample of what I would like to send: Data...
4
2568
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 from various excel lists, and then send the results via email to our various agents. I found some vb code online shown below, but Im a complete...
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 used serial port. thank you VB genius. a feedback is really appreciated!
12
13356
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 & "VAR:" & AddTabs(1) & Format(rsVar!, "currency") strOutput = strOutput & Chr(10) & Chr(10) strOutput = strOutput & "Position Value:" & AddTabs(1) &...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8132
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.