{"action":"created","issue":{"url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/40","labels_url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/40/comments","events_url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/40/events","html_url":"https://github.com/Quobject/SocketIoClientDotNet/issues/40","id":63944153,"number":40,"title":"Calling Emit within EVENT_CONNECT callback has massive delay","user":{"login":"DuBistKomisch","id":703055,"avatar_url":"https://avatars.githubusercontent.com/u/703055?v=3","gravatar_id":"","url":"https://api.github.com/users/DuBistKomisch","html_url":"https://github.com/DuBistKomisch","followers_url":"https://api.github.com/users/DuBistKomisch/followers","following_url":"https://api.github.com/users/DuBistKomisch/following{/other_user}","gists_url":"https://api.github.com/users/DuBistKomisch/gists{/gist_id}","starred_url":"https://api.github.com/users/DuBistKomisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DuBistKomisch/subscriptions","organizations_url":"https://api.github.com/users/DuBistKomisch/orgs","repos_url":"https://api.github.com/users/DuBistKomisch/repos","events_url":"https://api.github.com/users/DuBistKomisch/events{/privacy}","received_events_url":"https://api.github.com/users/DuBistKomisch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-24T09:10:06Z","updated_at":"2015-06-17T21:41:00Z","closed_at":null,"body":"Based on the brief example given in the project's readme, I used something like this code:\r\n\r\n```\r\nsocket = IO.Socket(\"http://123.45.67.89:1234/\");\r\nsocket.On(Socket.EVENT_CONNECT, () =>\r\n{\r\n  JObject jout = JObject.FromObject(new { foo = Bar, hello = \"world\" });\r\n  socket.Emit(\"test\", jout);\r\n});\r\n```\r\n\r\nHowever, it takes anywhere from 20 to 60 seconds to actually emit the message and appear on the server. However, after that message eventually gets sent, any subsequent Emit calls (e.g. from an On(\"test\", ...) callback, or the UI) work instantly, as expected.\r\n\r\nEven if no JSON data is passed with the Emit, same thing happens.\r\n\r\nThe rest of the method this is inside of simply defines a bunch more event listeners for messages, so I don't really see what's causing it. I also tried disabling AutoConnect with an IO.Options parameter and calling socket.Connect() after registering all the callbacks, but same issue.\r\n\r\nI came up with a workaround which simply defers the Emit to not occur immediately within the callback by using a one-off Timer:\r\n\r\n```\r\nsocket.On(Socket.EVENT_CONNECT, () =>\r\n{\r\n  t = new Timer(1.0);\r\n  t.Elapsed += (object sender, ElapsedEventArgs e) =>\r\n  {\r\n    t.Stop();\r\n    JObject jout = JObject.FromObject(new { foo = Bar, hello = \"world\" });\r\n    socket.Emit(\"test\", jout);\r\n  };\r\n  t.Start();\r\n});\r\n```\r\n\r\nThis seems like a bit of an issue given it's such an essential use case though, so I thought I should bring it up here."},"comment":{"url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/comments/112959485","html_url":"https://github.com/Quobject/SocketIoClientDotNet/issues/40#issuecomment-112959485","issue_url":"https://api.github.com/repos/Quobject/SocketIoClientDotNet/issues/40","id":112959485,"user":{"login":"TadeoArmenta","id":10125168,"avatar_url":"https://avatars.githubusercontent.com/u/10125168?v=3","gravatar_id":"","url":"https://api.github.com/users/TadeoArmenta","html_url":"https://github.com/TadeoArmenta","followers_url":"https://api.github.com/users/TadeoArmenta/followers","following_url":"https://api.github.com/users/TadeoArmenta/following{/other_user}","gists_url":"https://api.github.com/users/TadeoArmenta/gists{/gist_id}","starred_url":"https://api.github.com/users/TadeoArmenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TadeoArmenta/subscriptions","organizations_url":"https://api.github.com/users/TadeoArmenta/orgs","repos_url":"https://api.github.com/users/TadeoArmenta/repos","events_url":"https://api.github.com/users/TadeoArmenta/events{/privacy}","received_events_url":"https://api.github.com/users/TadeoArmenta/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T21:41:00Z","updated_at":"2015-06-17T21:41:00Z","body":"maybe you could try reducing the connection timeout\r\n\r\nQuobject.SocketIoClientDotNet.Client.IO.Options OPT = new Quobject.SocketIoClientDotNet.Client.IO.Options();\r\nOPT.Timeout = 3000;\r\nsocket = IO.Socket(\"http://123.45.67.89:1234/\", OPT);\r\nsocket.On(Socket.EVENT_CONNECT, () =>\r\n{\r\n  JObject jout = JObject.FromObject(new { foo = Bar, hello = \"world\" });\r\n  socket.Emit(\"test\", jout);\r\n});\r\nsocket.On(Socket.EVENT_CONNECT_ERROR,(data) =>\r\n{\r\n  Debug.WriteLine(\"Error : \" + data );\r\n});\r\n"}}