{"action":"created","issue":{"url":"https://api.github.com/repos/quamotion/madb/issues/29","repository_url":"https://api.github.com/repos/quamotion/madb","labels_url":"https://api.github.com/repos/quamotion/madb/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/quamotion/madb/issues/29/comments","events_url":"https://api.github.com/repos/quamotion/madb/issues/29/events","html_url":"https://github.com/quamotion/madb/issues/29","id":148436135,"number":29,"title":"Trouble connecting to ADB server on OS X","user":{"login":"PhilippCh","id":966567,"avatar_url":"https://avatars.githubusercontent.com/u/966567?v=3","gravatar_id":"","url":"https://api.github.com/users/PhilippCh","html_url":"https://github.com/PhilippCh","followers_url":"https://api.github.com/users/PhilippCh/followers","following_url":"https://api.github.com/users/PhilippCh/following{/other_user}","gists_url":"https://api.github.com/users/PhilippCh/gists{/gist_id}","starred_url":"https://api.github.com/users/PhilippCh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PhilippCh/subscriptions","organizations_url":"https://api.github.com/users/PhilippCh/orgs","repos_url":"https://api.github.com/users/PhilippCh/repos","events_url":"https://api.github.com/users/PhilippCh/events{/privacy}","received_events_url":"https://api.github.com/users/PhilippCh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"qmfrederik","id":9918129,"avatar_url":"https://avatars.githubusercontent.com/u/9918129?v=3","gravatar_id":"","url":"https://api.github.com/users/qmfrederik","html_url":"https://github.com/qmfrederik","followers_url":"https://api.github.com/users/qmfrederik/followers","following_url":"https://api.github.com/users/qmfrederik/following{/other_user}","gists_url":"https://api.github.com/users/qmfrederik/gists{/gist_id}","starred_url":"https://api.github.com/users/qmfrederik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmfrederik/subscriptions","organizations_url":"https://api.github.com/users/qmfrederik/orgs","repos_url":"https://api.github.com/users/qmfrederik/repos","events_url":"https://api.github.com/users/qmfrederik/events{/privacy}","received_events_url":"https://api.github.com/users/qmfrederik/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-04-14T17:50:51Z","updated_at":"2016-04-15T14:57:36Z","closed_at":null,"body":"Hi there!\r\n\r\nI'm currently looking into porting my codebase (C# .NET Framework 4.5.2 with VS2015) to OS X (and further Linux) and I'm running into an issue while connecting to the ADB server using `AdbClient.Instance.Connect(hostname);` where hostname is a local network IP á la 192.168.0.x.\r\n\r\nThe error returned is\r\n\r\n```C#\r\n[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException: Connection refused\r\n  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) <0x86a98c0 + 0x00167> in <filename unknown>:0 \r\n  at SharpAdbClient.TcpSocket.Connect (System.Net.EndPoint endPoint) <0x86a9868 + 0x0001f> in <filename unknown>:0 \r\n  at SharpAdbClient.AdbSocket..ctor (System.Net.EndPoint endPoint) <0x86a75c8 + 0x0007c> in <filename unknown>:0 \r\n  at SharpAdbClient.Factories+<>c.<Reset>b__17_0 (System.Net.EndPoint endPoint) <0x86a7580 + 0x0002f> in <filename unknown>:0 \r\n  at SharpAdbClient.AdbClient.Connect (System.Net.DnsEndPoint endpoint) <0x86b4570 + 0x00039> in <filename unknown>:0 \r\n  at SharpAdbClient.AdbClientExtensions.Connect (IAdbClient client, System.String host) <0x86b4390 + 0x00076> in <filename unknown>:0 \r\n  at CoCB.Utils.AdbHelper.ConnectToHost (System.String hostname) <0x86b4330 + 0x0001b> in <filename unknown>:0 \r\n  at CoCB.Utils.AdbHelper.Connect () <0x86b4298 + 0x0006b> in <filename unknown>:0 \r\n  at CoCB.Program.Main () <0x6bdf38 + 0x0012b> in <filename unknown>:0 \r\n```\r\n\r\nThe same code is confirmed to work on Windows 10. I can see that under Unix based operating systems, you take a different approach to connecting to the ADB server, which connects to a socket at \"/tmp/5037\". I'm not very proficient with *nix sockets, so I don't know if I'm doing something wrong here. I can't find the requested socket file in the file system (through Finder or ls).\r\n\r\nThe server is started through `AdbServer.StartServer(\"/Users/xxx/Library/Android/sdk/platform-tools/adb\", true);` and returns code 'Started' so I'm assuming the server was started successfully. But somehow the connection still fails. If I try to open a connection with \r\n```C#\r\nvar socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);\r\n\r\nsocket.Connect (\"192.168.0.106\", 5555);\r\n``` \r\nthe connection opens just fine (socket.Connected is True).\r\n\r\nWould you have any idea where I could start with this?\r\n\r\nCheers\r\nPhilipp\r\n\r\n**EDIT**\r\n\r\nReplacing TcpSocket.cs\r\n\r\n```C#\r\n//this.socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);\r\nthis.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);\r\n``` \r\n\r\nand AdbServer.cs\r\n\r\n```C#\r\n//EndPoint = new UnixEndPoint($\"/tmp/{AdbServerPort}\");\r\nEndPoint = new IPEndPoint(IPAddress.Loopback, AdbServerPort);\r\n``` \r\n\r\nseems to connect to the device. I can query the DeviceData class, but I haven't tried sending any commands yet. Is there any specific reason you are using Mono.Posix specific endpoints for OS X and Linux?"},"comment":{"url":"https://api.github.com/repos/quamotion/madb/issues/comments/210493368","html_url":"https://github.com/quamotion/madb/issues/29#issuecomment-210493368","issue_url":"https://api.github.com/repos/quamotion/madb/issues/29","id":210493368,"user":{"login":"qmfrederik","id":9918129,"avatar_url":"https://avatars.githubusercontent.com/u/9918129?v=3","gravatar_id":"","url":"https://api.github.com/users/qmfrederik","html_url":"https://github.com/qmfrederik","followers_url":"https://api.github.com/users/qmfrederik/followers","following_url":"https://api.github.com/users/qmfrederik/following{/other_user}","gists_url":"https://api.github.com/users/qmfrederik/gists{/gist_id}","starred_url":"https://api.github.com/users/qmfrederik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmfrederik/subscriptions","organizations_url":"https://api.github.com/users/qmfrederik/orgs","repos_url":"https://api.github.com/users/qmfrederik/repos","events_url":"https://api.github.com/users/qmfrederik/events{/privacy}","received_events_url":"https://api.github.com/users/qmfrederik/received_events","type":"User","site_admin":false},"created_at":"2016-04-15T14:57:35Z","updated_at":"2016-04-15T14:57:35Z","body":"Hi @PhilippCh ,\r\n\r\nThanks for the detailed bug report!\r\n\r\nI looked into this, and you are correct, a normal TCP endpoint is used by adb on all systems.\r\n\r\nI was misled by the one exception - Debian (and hence also Ubuntu) [has manually patched adb](https://anonscm.debian.org/cgit/android-tools/android-tools.git/tree/debian/patches/use-local-socket.patch?h=debian/5.1.1.r29-2) to listen on local TCP sockets and Ubuntu was the Unix system on which we tested.\r\n\r\nSo the correct behavior would be to use TCP sockets on all operating systems, except for Debian Linux and derivatives.\r\n\r\nI'll fix it for OS X, and keep this issue open to track a solution for Linux."}}