Hello
I am fighting to sync a C++ client with a C# server, I have managed to create a byte array in C++ stored as char* to be sent over the network to the server written in C#.
on the C# side, I get the data on a byte array which I successfully convert to an object with similarities to the object the data came from in C++, then I construct an object with the reply, encode it to a byte array and I send it back to the client in C++
Here I am stuck, while getting the data in C++ it is not arriving complete, or I am missing where to look for that data.
ok, and example to be more precise..
fom C++
I construct a char* representation of a byte array for this data
unsigned short = 6
char[2] = "OP"
char = 101
char = 0
the first value is the length of the package, a short is 2 bytes, a char is one byte, that makes 6 bytes total so, the byte array is this
[6,0,79,80,101,0], the first two bytes is the short number in little endian becuase of intel arch, the 79 is the O, the 80 is the P, and the rest as is.
on C#, I get this information correctly and I decode it to the object with no problem, then I code a new message.
ushort = 6
byte[2] = OK
byte = 101
byte = 0
[6,0,79,75,101,0] and I send this to C++.
on C++ I get the info on a char* variable, becuase sockets are this way there, but here come the problem, the second byte "0" I think is percieved on the char* as a null character terminator, so, I end up with only 6 on the data received from the network
anyone can give a tip about how to deal with this? 0 byte value on the network package.
Thanks
Juan
3 2217
To recap: the C++ to C# is working fine, but the C# to C++ is only giving you a string with a 6 in it (as far as you can tell).
This could definitely be a string vrs binary issue, but there are ways to check. First you need to see how many bytes of data you're getting over the socket. What are you using to read the socket?
You need some IO routine that reads binary data. In C, fread and fwrite work with buffers and tell you how much they got/sent. You can't use printf with a string because of the zero problem. In C++, istreams have a read method that also fills up a buffer.
Once you know how many bytes made it to C++, then you figure out where the problem is.
Hello
I am getting the data from C# on the C++ side this way
err = recv(m_ClientSocket, Buff, 65535, 0);
err is now 6,
and the 65535 is the max my data can be.
so, on this Buff variable, strlen do not apply? how I can get the data this way?
I need to put the first 2 bytes, into a short, the third and forth into char[2], and the other 2 in 2 char variables, in the case that the info is bigger, that mean that the information from C# is not only one message, but that is another story, I need to figure out how to get one message and do the same in case more than one arrive in the reame recv.
If you are getting '6' as the return value of 'recv' function, then it means the 6 bytes has been received successfully and is safe in the buffer. So, you have to concentrate in how you handle the buffer.
For Eg: Did you try using 'memcpy' function for extracting data or Just writing the whole buffer to a file [ fwrite(buff, 1, 6, fp) ]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sathyaish |
last post by:
I am using MCI (winmm.dll) to read, record and playback sound. For
now, I am doing this with disk files instead of realtime doing it
straight from the memory. If I want to stream/relay/transmit...
|
by: Ricardo Quintanilla |
last post by:
i have a code that sends data to a socket listening over as400 platform,
the socket responds to me as a "byte array".
then i need to convert the "byte array" into a string.
the problem is that...
|
by: TRW1313 |
last post by:
I'm looking to populate a byte array of some fixed size to send out over
a UDP connection. The data in the byte array is mixed between characters
and binary.
I'm a beginner to this language.
...
|
by: Guoqi Zheng |
last post by:
I am really do not know so much about byte/bit, etc.
Question, if I defined a byte(), how can I add a single byte to it?
what I want is that I have an array of bytes, I loop that array, look at...
|
by: Danny |
last post by:
I am working on a project where I will receive xml documents from clients
machines as a byte array. They will use the web browser navigate method to
post the data to my ASP.NET page. I then pick up...
|
by: O.B. |
last post by:
I'm trying to do a static_cast at runtime in C# and as I understand it,
"as" is the keyword to use. Unfortunately, the compiler is trying to do
the cast a compilation time. See below.
/*...
|
by: MimiMi |
last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for.
I think I am using the same type of...
|
by: MimiMi |
last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for.
I think I am using the same type of...
|
by: ist |
last post by:
Hi,
I am trying to get (and transfer over ASP.NET) some encrypted data
from some MySQL fields. Since the data contains many unicode
characters, I tried to get the data as a series of ASCII...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |