{"action":"created","issue":{"url":"https://api.github.com/repos/sochix/TLSharp/issues/264","repository_url":"https://api.github.com/repos/sochix/TLSharp","labels_url":"https://api.github.com/repos/sochix/TLSharp/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/sochix/TLSharp/issues/264/comments","events_url":"https://api.github.com/repos/sochix/TLSharp/issues/264/events","html_url":"https://github.com/sochix/TLSharp/issues/264","id":184775319,"number":264,"title":"HTTP Transport","user":{"login":"andrew-maksimov","id":16094779,"avatar_url":"https://avatars.githubusercontent.com/u/16094779?v=3","gravatar_id":"","url":"https://api.github.com/users/andrew-maksimov","html_url":"https://github.com/andrew-maksimov","followers_url":"https://api.github.com/users/andrew-maksimov/followers","following_url":"https://api.github.com/users/andrew-maksimov/following{/other_user}","gists_url":"https://api.github.com/users/andrew-maksimov/gists{/gist_id}","starred_url":"https://api.github.com/users/andrew-maksimov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrew-maksimov/subscriptions","organizations_url":"https://api.github.com/users/andrew-maksimov/orgs","repos_url":"https://api.github.com/users/andrew-maksimov/repos","events_url":"https://api.github.com/users/andrew-maksimov/events{/privacy}","received_events_url":"https://api.github.com/users/andrew-maksimov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sochix/TLSharp/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/sochix/TLSharp/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-24T08:13:31Z","updated_at":"2016-10-27T10:01:55Z","closed_at":"2016-10-25T09:27:47Z","body":"Now TLSharp supports one transport (TCP). I would try to write another transport (HTTP).\r\n\r\nSomeone tell me where best to start, and which way to go? =)"},"comment":{"url":"https://api.github.com/repos/sochix/TLSharp/issues/comments/256600057","html_url":"https://github.com/sochix/TLSharp/issues/264#issuecomment-256600057","issue_url":"https://api.github.com/repos/sochix/TLSharp/issues/264","id":256600057,"user":{"login":"andrew-maksimov","id":16094779,"avatar_url":"https://avatars.githubusercontent.com/u/16094779?v=3","gravatar_id":"","url":"https://api.github.com/users/andrew-maksimov","html_url":"https://github.com/andrew-maksimov","followers_url":"https://api.github.com/users/andrew-maksimov/followers","following_url":"https://api.github.com/users/andrew-maksimov/following{/other_user}","gists_url":"https://api.github.com/users/andrew-maksimov/gists{/gist_id}","starred_url":"https://api.github.com/users/andrew-maksimov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrew-maksimov/subscriptions","organizations_url":"https://api.github.com/users/andrew-maksimov/orgs","repos_url":"https://api.github.com/users/andrew-maksimov/repos","events_url":"https://api.github.com/users/andrew-maksimov/events{/privacy}","received_events_url":"https://api.github.com/users/andrew-maksimov/received_events","type":"User","site_admin":false},"created_at":"2016-10-27T10:01:55Z","updated_at":"2016-10-27T10:01:55Z","body":"Maybe someone will tell you where I'm confused.\r\nI am trying to implement the http-transport. When you try to get the answer - Error 404.\r\n\r\n```\r\n    public class HttpTransport : ITransport, IDisposable\r\n    {\r\n        private readonly HttpWebRequest httpWebRequest;\r\n        private int sendCounter = 0;\r\n        \r\n        public HttpTransport(string address, int port)\r\n        {\r\n            httpWebRequest = (HttpWebRequest)WebRequest.Create(\"http://\" + address);\r\n        }\r\n\r\n        public async Task Send(byte[] packet)\r\n        {\r\n            var data = packet;\r\n\r\n            httpWebRequest.Method = \"POST\";\r\n            httpWebRequest.ContentType = \"application/x-www-form-urlencoded ; charset=UTF-8\";\r\n            httpWebRequest.ContentLength = data.Length;\r\n\r\n            using (var stream = httpWebRequest.GetRequestStream())\r\n            {\r\n                await stream.WriteAsync(data, 0, data.Length);\r\n            }\r\n            \r\n            sendCounter++;\r\n        }\r\n\r\n        public async Task<TcpMessage> Receieve()\r\n        {\r\n            var response = (HttpWebResponse)httpWebRequest.GetResponse();\r\n            var stream = response.GetResponseStream();\r\n\r\n            var packetLengthBytes = new byte[4];\r\n            if (await stream.ReadAsync(packetLengthBytes, 0, 4) != 4)\r\n                throw new InvalidOperationException(\"Couldn't read the packet length\");\r\n            int packetLength = BitConverter.ToInt32(packetLengthBytes, 0);\r\n\r\n            var seqBytes = new byte[4];\r\n            if (await stream.ReadAsync(seqBytes, 0, 4) != 4)\r\n                throw new InvalidOperationException(\"Couldn't read the sequence\");\r\n            int seq = BitConverter.ToInt32(seqBytes, 0);\r\n\r\n            int readBytes = 0;\r\n            var body = new byte[packetLength - 12];\r\n            int neededToRead = packetLength - 12;\r\n\r\n            do\r\n            {\r\n                var bodyByte = new byte[packetLength - 12];\r\n                var availableBytes = await stream.ReadAsync(bodyByte, 0, neededToRead);\r\n                neededToRead -= availableBytes;\r\n                Buffer.BlockCopy(bodyByte, 0, body, readBytes, availableBytes);\r\n                readBytes += availableBytes;\r\n            }\r\n            while (readBytes != packetLength - 12);\r\n\r\n            var crcBytes = new byte[4];\r\n            if (await stream.ReadAsync(crcBytes, 0, 4) != 4)\r\n                throw new InvalidOperationException(\"Couldn't read the crc\");\r\n            int checksum = BitConverter.ToInt32(crcBytes, 0);\r\n\r\n            byte[] rv = new byte[packetLengthBytes.Length + seqBytes.Length + body.Length];\r\n\r\n            Buffer.BlockCopy(packetLengthBytes, 0, rv, 0, packetLengthBytes.Length);\r\n            Buffer.BlockCopy(seqBytes, 0, rv, packetLengthBytes.Length, seqBytes.Length);\r\n            Buffer.BlockCopy(body, 0, rv, packetLengthBytes.Length + seqBytes.Length, body.Length);\r\n            var crc32 = new Ionic.Crc.CRC32();\r\n            crc32.SlurpBlock(rv, 0, rv.Length);\r\n            var validChecksum = crc32.Crc32Result;\r\n\r\n            if (checksum != validChecksum)\r\n            {\r\n                throw new InvalidOperationException(\"invalid checksum! skip\");\r\n            }\r\n\r\n            return new TcpMessage(seq, body);\r\n        }\r\n    }\r\n```\r\n"}}
{"actor":{"display_login":"andrew-maksimov"}}