LiveOrDevTrying / Tcp.NET

Tcp.NET provides an easy-to-use and customizable Tcp Server and Tcp Client. The server is created using a TcpListener. The server and client can be used for non-SSL or SSL connections and authentication (including client and server ssl certification validation) is provided for identifying the clients connected to your server. Both client and server are created in .NET Standard and use async await functionality.
Apache License 2.0
42 stars 10 forks source link

Can't connect from my android phone #7

Closed FarooqKhattak closed 1 year ago

FarooqKhattak commented 1 year ago

Hi, I am trying to connect with the server from my phone on ip 127.0.0.1, but i got no socket found exception. although my pc and phone are on the same network too.

LiveOrDevTrying commented 1 year ago

Try using the IP address of your machine assigned by your router. 127.0.0.1 is a loopback and doesn't get exposed on the network. Make sure your firewall allows the port

FarooqKhattak commented 1 year ago

Thanks connection is established. and now i copied send message code from repository. but it doesn't recognize it's own methods. image

Note: i only installed Tcp.Net.Server package bcz i only need that. my client is my mobile.

FarooqKhattak commented 1 year ago

Moreover, as we know that i install Tcp.Net.Server package only. so according to the documentation, i should have found the server.asyncStart() method. but unfortunately, i don't have server.asyncStart or Stop method available except those simple Start and Stop methods. Why is that?

LiveOrDevTrying commented 1 year ago

Apologies, the documentation is a bit outdated and its on my short-term todos to update it.

Per your image: Connections is an IEnumerable or IEnumerable<IdentityTcpServer>, depending on which server you use. You can do:

The SendToConnectionAsync function is erroring for 2 reasons:

  1. Packet has been deprecated. The 2 new functions are:

Get rid of Packet and change your message to either string or byte[]

  1. SendToConnectionAsync is not contained in an async method. Wrap it in a Task -> e.g.

Lastly, TcpListener, which is what is used for the underlying server socket, only exposes Start() and Stop(). They are not async since there is no delay - the socket just opens or closes without waiting for anothre task. Its a synchronous operation to start and stop and TcpListener.

The documentation is old and I need to update it. Apologies again

FarooqKhattak commented 1 year ago

Thanks for sharing. It is very helpful

On Fri, Apr 14, 2023, 3:27 AM Rob Engel @.***> wrote:

Apologies, the documentation is a bit outdated and its on my short-term todos to update it.

Per your image: Connections is an IEnumerable or IEnumerable, depending on which server you use. You can do:

  • ConnectionTcpServer[] connections = server,Connections.ToArray();

The SendToConnectionAsync function is erroring for 2 reasons:

  1. Packet has been deprecated. The 2 new functions are:

    • Task SendToConnectionAsync(string message, Z connection, CancellationToken cancellationToken = default);
    • Task SendToConnectionAsync(byte[] message, Z connection, CancellationToken cancellationToken = default);

Get rid of Packet and change your message to either string or byte[]

  1. SendToConnectionAsync is not contained in an async method. Wrap it in a Task -> e.g.

    • Task.Run(async () => { await server.SendToConnectiobAsync()});

Lastly, TcpListener, which is what is used for the underlying server socket, only exposes Start() and Stop(). They are not async since there is no delay - the socket just opens or closes without waiting for anothre task. Its a synchronous operation to start and stop and TcpListener.

The documentation is old and I need to update it. Apologies again

— Reply to this email directly, view it on GitHub https://github.com/LiveOrDevTrying/Tcp.NET/issues/7#issuecomment-1507685418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AURBQLNORX5RSI3VDGIXERLXBB4ULANCNFSM6AAAAAAWZ4AFY4 . You are receiving this because you authored the thread.Message ID: @.***>