Code:
_senddata = System.Text.Encoding.ASCII.GetBytes(("STAT" + vbCrLf).ToCharArray())
_netstream.Write(_senddata, 0, _senddata.Length)
MsgBox(_stmreader.ReadLine)
the MsgBox here looks very suspicious. The trouble is straight after you write to the stream you are trying to read a response. This assumes that the response is instant and that the other app and comms have been quicker than Msgbox. This is unlikely to be the case. I would expect some kind of event be raised from the other app and your application lookiing out for that event. Only then can you ensure that you are receiving all data in the stream. Check out Async communication there are loads of examples out there. I suspect this is what you really need.
also anything you read, you may need to use Decode as opposed to Encode
Here is an example of mine the uses Async. I happen to be passing xml data to a service and then am waiting for a new xml document to be returned. There is no reason why you cant use this principal in your code.
On the main thread create a background worker, by doing this it opens a new thread and then waits for this thread to return. My code is in C# but you can easily convert to VB.
Code:
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
Now we have this established worker_RunWorkerCompleted is the event that receives the returning data, so this is where you would place your msgBox and do anything with the incoming stream.
Code:
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
callback.OnRatabaseCallback(xmlData);
}
Code:
protected void worker_DoWork(object sender, DoWorkEventArgs e)
{
try
{......
The worker_DoWork is where you make the call to the other application.
All of this is in a WCF Service, but it doesn't have to be