Difficulties in programming of messenger Telegram on C#

2.8k views Asked by At

I try to send a code(TLRequestAuthSendCode) but it doesn't come. In what there can be a problem?

Part of code:

TLContext tlContext = new TLApiContext();
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(connections[0].getAddress(), (int)connections[0].getPort());
TLRequestAuthSendCode tlRequestAuthSendCode = new TLRequestAuthSendCode("PHONE_NUMBER",
0, 19114, "TOKEN", "en");
tlRequestAuthSendCode.serializeBody(new StreamWriter(tcpClient.GetStream()));
3

There are 3 answers

0
Charles Okwuagwu On BEST ANSWER

You can get started with this, but I have written it in vb.net, not C#.

It will walk you through getting started building your own Telegram-API from scratch.

Also try and get familiar with the online documentation, it's hard but the step by step explanation I gave in that link above on generating your AuthKey, should get you started.

Good Luck

0
Luca On

can you debug your code and tell if

tcpClient.Connect(connections[0].getAddress(),

Connections[0] has a value?

I'd suggest you change your code to the following:

        public void run() {
        connections = new ConnectionInfo[]{
            new ConnectionInfo(1, 0, "149.154.167.40", 443)
        };

        apiState = new ApiState(connections);
        doReqCode(connections);

        private void doReqCode(connections){

        var args = new SocketAsyncEventArgs();

I don't see where the code could break, maybe a more detailed description of your problem would be helpful

0
sch4um4 On

TcpClient tcpClient = new TcpClient();

As i tried the code, it mostly seemd to me as if the port was either blocked or already in use. Maybe u have a permission problem there. At least i didnt manage to get a Socket to work with the code like that. Also i didnt dive to deep in your code, but you are using port 443. This is a reserved port with limited access.