C++/CLI using XmlWriter with TcpClient not writing - c++-cli

I hope you'll forgive me if this is obvious; just starting out with c++/cli. I'm using some sample C# code to generate this but am using cli mode in a legacy c++ application so I'm having trouble in translation. Not easy finding samples on the web.
This is a snippet of code. An XDocument is passed into this code. I've checked it by writing to a file and the resulting xml file looks as it should (identical to the sample C# app). The tcpclient call seems to work, if I change the address, it throws an exception. I also see the connection established in a TCP Sniffer.
The request->WriteTo doesn't work - the sniffer shows no data written and the device doesn't respond.
Further, the XmlReader::Create call locks everything up.
Clearly, I've got something wrong in how I'm setting up the writer or the stream.
Any ideas?
Thanks.
TcpClient ^ socket = gcnew TcpClient(address,port); // connect to device
NetworkStream ^ stream;
stream = socket->GetStream(); // get stream.
XmlWriter ^writer = XmlWriter::Create(stream,xmlWrite); // Create writer
request->WriteTo(writer); // Write XDocument to stream.
XmlReader ^reader = XmlReader::Create(stream,xmlRead);

I don't know if this is good form or not but I found the answer so I'll post here in case anyone else has a similar problem:
After
request->WriteTo(writer)
I added
writer->Flush().
Odd that the C# example I was working from didn't require this so if anyone has any insight into why the difference, I'd love to hear it.

Related

data channel using libjingle C/C++

I am looking for a very basic example of establishing a data channel using WebRTC. The peer_connection examples given are for audio/video and I am not able to run them to understand the code flow and write code for data channel on my own. I have done this using JavaScript for browser, now want to do the same for native application.
Have you check the peerconnection.cc for data channel creation API?
I saw this:
talk_base::scoped_refptr<DataChannelInterface>
PeerConnection::CreateDataChannel(
const std::string& label,
const DataChannelInit* config) {
talk_base::scoped_refptr<DataChannelInterface> channel(
session_->CreateDataChannel(label, config));
if (!channel.get())
return NULL;
observer_->OnRenegotiationNeeded();
return DataChannelProxy::Create(signaling_thread(), channel.get());
}
So in the peerconnection_client example, I think you can try create the data channel using peerconnection in the conductor.cc using peer_connection_ inside AddStreams and keep the data channel instance, then try send data using it after the answer is received.
Unfortunately I don't have the compilation env now to I can not try this myself.
Hope you can do it.
I was using an old revision of webrtc. There is an example called PCP_MAIN. This example demonstrates the basic file transfer between two peers. However this uses pseudo TCP. This is little hard to getting it work as data channels. Probably you might want to look something around RTP data channels.
I'm curious to know about some examples using SCTP.

Reading Xml from an absolute path

I need to access a remote Xml document from a WCF service. Right now I have:
XmlReader reader = XmlReader.Create("path");
But since the Xml doc is elsewhere on our network I need to give the XmlReader an absolute path, as opposed to having it look deeper in the project folder. How do I do this? I've found surprisingly little information about this. It seems like this should be a simple thing to do. Any help is appreciated!
Thanks
You can use overload that accepts Stream parameters as follows:
using (FileStream fileStream = new FileStream(#"\\computername\shared path"))
using (XmlReader reader = XmlReader.Create(fileStream))
{
// perform your custom code with XmlReader
}
Please note that you need appropriate permission to open remote stream. In WCF service context you may need to use impersonation.

kSoap-2 android nullpointer exception

I am working with ksoap2 for android and I am sending SOAP requests. I was googling for a whole day and couldn't find solution for my problem. The first problem was with i:type, my service was returning fault for requests with i:type, so I found that this can be fixed using
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
instead of
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
and that fixed the i:type problem. Now the generated request doesn't contain i:type and if I send it using SOAP UI it works fine, but now I get NullPointerException
in this line
httpTransport.call(DEFAULT_SOAP_ACTION, envelope);
Can anyone help me out with this? If u need my code I can post it. I also tried using different versions of ksoap .jar file and it didn't help.
Maybe someone will need this.
I solved this by setting types explicitly (for each PropertyInfo there is .setType function which receives type class String.class etc.) and use
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
and using that removes i:type from the soap request. Hope it will help someone.

Sending a file from a java client to a server using wcf method?

I want to build a wcf web service so that the client and the server would be able to transfer files between each other. Do you know how I can achieve this? I think I should turn it into a byte array but I have no idea how to do that. The file is also quite big so I must turn on streamed response.
It sounds like you're on the right track. A quick search of the interwebz yielded this link: http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP
Your question indicates that you want to send a file from a java client to a WCFd endpoint, but the contents of your question indicate that this should be a bidirectional capability. If this is the case, then you'll need to implement a service endpoint on your client as well. As far as that is concerned, I cannot be of much help, but there are resources out there like this SO question: In-process SOAP service server for Java
As far as practical implementation, I would think that using these two links you should be able to produce some code for your server and client.
As far as reading all bytes of a file, in C# you can use: File.ReadAllBytes It should work as in the following code:
//Read The contents of the file indicated
string fileName = "/path/to/some/file";
//store the binary in a byte array
byte[] buffer = File.ReadAllBytes(fileName);
//do something with those bytes!
Be sure to use the search function in the future:

how to hide http request using vb.net

I'm developing new app. This is app need to get information from my website so I use HTTP request using vb.net.
Sub Main()
'Address of URL
Dim URL As String = http://whatever.com
' Get HTML data
Dim client As WebClient = New WebClient()
Dim data As Stream = client.OpenRead(URL)
Dim reader As StreamReader = New StreamReader(data)
Dim str As String = ""
str = reader.ReadLine()
Do While str.Length > 0
Console.WriteLine(str)
str = reader.ReadLine()
Loop
My problem is , I found an app called fiddler http://www.fiddler2.com/fiddler2/
This app could find all HTTP request that maked using my app , so this put my website at risk.
Is There any way how to hide HTTP request from been detected ????
I'm not familiar with this "fiddler" product, but just from reading the page that you reference, it is something that runs on the user's machine and monitors traffic between that computer and the Internet. I don't see how it would be even theoretically possible to prevent this. Signals are moving over wires leaving the user's computer. He presumably has physical access to his own computer. If nothing else, he could attach something to the cable coming out the back of the computer that monitors the signals moving over the wire.
You could encrypt messages so that it's difficult for the user to interpret what they mean, but you can't stop him from reading the message as it was sent.
I wonder, by the way, how it is a security problem for a user to know what messages are being sent from his own computer. Are you trying to hide what you are doing from the person using your program? Frankly, if I discovered that an application I have on my computer was trying to hide what it was doing from me, I would immediately delete it. Why would someone want to hide what he's doing to MY computer unless what he is doing is something sinister, trying to steal my personal data or some such?
Just to be slightly sarcastic, your question sounds a little like asking, When I visit a business associate, how can I prevent him from finding out out what I did in his office when he stepped out for a few minutes?
There is a way using the Proxy method just add this Code in the HTTP request:
Request.Proxy = New WebProxy()
cause how fiddler works it sets itself as the proxy using the above code it cannot set fiddler proxy and thats how you stop it from reading anything