Skip to content

NetworkStream seams to be writing to socket but stream.DataAvailable in Reciever is always false #3

Open
@sturlath

Description

@sturlath

What is this?

I have this quite elegant code that just sends data on a socket and should invoke an event when it receives a response on a socket it should be listening to.

My issue with this code is with WinForms and Xamarin.Forms (UI frameworks) where some threading is interfering with the "send to socket" method.

UPDATE 9. March

Thanks to LimGeomJe the ServiceConsole is now updated and can receive data from the client so the problem is why the client can't receive data back from the service

Usage

How I use the code in my ItemsPage
ElegantCode

But sending data doesn't seem to work when in a UI environment it seems.

What works

Set ServerConsole and ClientConsole programs as startup and just pres F5.

StartupConsoles

And we get results flowing between them (I know I need to fix something there but It doesn't matter if I can't get this to work in an UI app)
ClientServerConsoleResults

So the code works logicly at least...

What doesn't work

If I set the Android project as a startup project and run the emulator and run ServiceConsole (Debug->Start new instance ) I can connect (press connect top right) to the service like you see here

Android_Connected_To_Service

But when I try to send data it does seem to be able to write to the socket (even though it never shows up in the ServiceConsole. See Client.SenderSendData method code
WritingSuccess

And probably because it can't write over to the server it can never get a response in the Receiver code that runs and runs. So the problem seems to be with the Send. See ClientReceiver code
ClientReceiver

When I then check the _stream properties I can see the port 14000 but the IP address is 33685514 that translates to 2.2.0.10 (not 10.0.2.2) according to this page. I don't know if that's anything...

My BOUNTY questions

  1. Why NetworkStream seem to be writing to the stream without sending the data to ServiceConsole, only when in a UI framework (Xamarin or WinForms)
  2. How can I send data to the service and receive data back with this architecture?
  3. I need this alert to fire always when a new data is sent from the client.
  4. Get this to work with the WinForms code could also help and will be awarded the bounty if nobody solved the Xamarin part.

Please don't be shy to try this code out for yourself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions