Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to socket cluster server #17

Open
kevinvella opened this issue Apr 27, 2018 · 16 comments
Open

Can't connect to socket cluster server #17

kevinvella opened this issue Apr 27, 2018 · 16 comments

Comments

@kevinvella
Copy link

I have a weird issue. When connecting to a a web socket server using the domain name in a xamarin mobile application, the server is logging "SocketProtocolError: Socket hung up" and from the client "System.InvalidOperationException: Operation already in progress"

When i try the code from a console application, the client connects fine and is able to send and receive data

ScClient.Offical version is 1.1.2

Socket Cluster server versions:
"dependencies": {
"connect": "3.0.1",
"express": "4.14.0",
"minimist": "1.1.0",
"morgan": "1.7.0",
"sc-errors": "^1.4.0",
"sc-framework-health-check": "^2.0.0",
"sc-hot-reboot": "^1.0.0",
"scc-broker-client": "^3.0.0",
"serve-static": "1.11.2",
"socketcluster": "^11.2.0",
"socketcluster-client": "^11.0.1"
}

public class SCService
    {
        private Socket socket;
        public SCService()
        {
            try
            {
                socket = new Socket("ws://bbtest.eu-4.evennode.com/socketcluster/");

                socket.SetReconnectStrategy(new ReconnectStrategy().SetMaxAttempts(30));
                socket.SetSslCertVerification(false);
                //socket.SetAuthToken("12345678");

                socket.SetListerner(new SocketClusterListener());
                socket.Connect();
            }
            catch (Exception ex)
            {

            }

        }

        public Socket Socket
        {
            get => socket;
        }
    }

    public class SocketClusterListener : IBasicListener
    {
        private string TAG = "SocketCluster";
        public void OnConnected(Socket socket)
        {
            Debug.WriteLine($"{TAG} - connected got called");
        }

        public void OnDisconnected(Socket socket)
        {
            Debug.WriteLine($"{TAG} - disconnected got called");
        }

        public void OnAuthentication(Socket socket, bool status)
        {
            Debug.WriteLine(status ? $"{TAG} - Socket is authenticated" : $"{TAG} - Socket is not authenticated");
        }

        public void OnSetAuthToken(string token, Socket socket)
        {
            socket.SetAuthToken(token);
            Debug.WriteLine($"{TAG} - on set auth token got called");
        }

        public void OnConnectError(Socket socket, SuperSocket.ClientEngine.ErrorEventArgs e)
        {
            Debug.WriteLine($"{TAG} - Error on Connection... {e.Exception}");
        }
    }
@sacOO7
Copy link
Owner

sacOO7 commented May 12, 2018

Hi @kevinvella , can you give me detailed log for this?

@kevinvella
Copy link
Author

Hi @sacOO7,
What information do you need? Running platforms, etc...?

@kevinvella
Copy link
Author

kevinvella commented May 13, 2018

Hi @sacOO7
Created a simple repository containg a console application and a xamarin forms application containing both android u ios. Repository here https://github.com/kevinvella/Socket-Cluster-Test

The exception that occurs on the xamarin forms app is the following:
SocketCluster - Error on Connection... System.InvalidOperationException: Operation already in progress at System.Net.Sockets.SocketAsyncEventArgs.SetLastOperation (System.Net.Sockets.SocketAsyncOperation op) [0x00021] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.177/src/Xamarin.iOS/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs:193 at System.Net.Sockets.Socket.InitSocketAsyncEventArgs (System.Net.Sockets.SocketAsyncEventArgs e, System.AsyncCallback callback, System.Object state, System.Net.Sockets.SocketOperation operation) [0x00030] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.177/src/Xamarin.iOS/mcs/class/System/System.Net.Sockets/Socket.cs:2727 at System.Net.Sockets.Socket.ReceiveAsync (System.Net.Sockets.SocketAsyncEventArgs e) [0x00073] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.177/src/Xamarin.iOS/mcs/class/System/System.Net.Sockets/Socket.cs:1375 at SuperSocket.ClientEngine.AsyncTcpSession.StartReceive () [0x0000c] in <dbd80dafc8794140aef5960a6254d156>:0 SocketCluster - disconnected got called

@sacOO7
Copy link
Owner

sacOO7 commented May 13, 2018

Hi @kevinvella , will take a look at it 👍

@sacOO7
Copy link
Owner

sacOO7 commented May 13, 2018

HI @kevinvella , I think it might be creating multiple service objects, so trying to connect to server multiple times. Can you move connect method somewhere else. It might work ...

@sacOO7
Copy link
Owner

sacOO7 commented May 13, 2018

Also make sure you have proper permission to have network access. I think currently the connection might be running on UI thread. So you need to connect to server on background thread probably.

@kevinvella
Copy link
Author

Connected to localhost with following

socket = new Socket("ws://127.0.0.1:8000/socketcluster/");

With the following it doesn't connect
socket = new Socket("ws://localhost:8000/socketcluster/");

Also tested with

Task.Run(() => 
  {
	socket.Connect();
  });

@sacOO7
Copy link
Owner

sacOO7 commented May 13, 2018 via email

@kevinvella
Copy link
Author

Will check later.
One more thing on the console app i'm able to connect to the socket using the domain name as in socket = new Socket("ws://localhost:8000/socketcluster/");

@sacOO7
Copy link
Owner

sacOO7 commented May 16, 2018

Hi @kevinvella , any updated on this? If it's working, I will be closing the issue 👍

@kevinvella
Copy link
Author

kevinvella commented May 20, 2018

Hi @sacOO7 ,

Sorry for not posting any sooner. I haven't had any time to test. I switched to PureSocketCluster and it worked due to a project time constrains.

I don't think the problem is in your lib. I think it's more related to how WebSocket4Net is working. Should we link this issue to WebSocket4Net repo issues?

@sacOO7
Copy link
Owner

sacOO7 commented May 21, 2018

Hi @kevinvella , it should work on both libraries. I will look into the issue 👍 .

@kevinvella
Copy link
Author

Ok. Thanks. If i have time, i will also take a look

@kevinvella
Copy link
Author

Hi,

Any updates on this?

@sacOO7
Copy link
Owner

sacOO7 commented Jun 5, 2018 via email

@kevinvella
Copy link
Author

Hi @sacOO7,
Ok. just fyi the hosting provider of the test app is evennode.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants