venomous0x / WhatsAPI

Interface to WhatsApp Messenger
2.59k stars 2.14k forks source link

how to keep server whats app account logged in always #1177

Open ivanlewis opened 8 years ago

ivanlewis commented 8 years ago

how to keep server whats app account logged in always?

I want to create a chat server where users will send messages or ask questions accordingly i want to send the replies.

Why there is need to use threading : while(true)

kirilydk commented 8 years ago

You just need to send a ping to whatsapp. It´s servers log you off after a timeout of 300 seconds.

Just initialize a new thread that sends a ping every random number between 100 and 300 seconds.

//Declaring thread private Thread threadPing; private volatile bool pingIsRunning = true;

//Method that sends ping private void ThreadPing() { while(pingIsRunning) { Random random = new Random(); Thread.Sleep(random.Next(100000, 300000)); WhatSocket.Instance.SendPing(); } }

Then start the thread when you logg in this.threadPing = new Thread(new ThreadStart(ThreadPing));

ivanlewis commented 8 years ago

Ok Thank you so much.

My second question is Why there is need to use
while (wa != null) { wa.PollMessages(); Thread.Sleep(100); continue; }