Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
Posts: 104
Registered: ‎09-25-2013
My Device: BB 10
My Carrier: BB 10

Software caused connection abort Error (Network Error)

Hi All,

 
I am getting Software caused connection abort Error while communicating with the server using qt Socket programming.
 
I have searched for the root cause for this Error in qt/BB 10 cascades, but could not found relevant information. 
 
In case of java,Software caused connection abort can be occurred for the following 
reasons,
 
Case -1. A connection abort was caused by the server or some software in between (e.g. firewall, proxy).
 
Case-2.when dealing with the big chunks of data.
 
Can I consider the same reasons for Qt/BB 10 also? If it is the case, 
 
I suppose case-1 may not be true because I am getting the data for a period of time, at some point of time getting Software caused connection abort error.
 
may be problem with  case-2 ,how to maintain the socket in connected mode until app is closed and communicate with the server to read and write data irrespective of the data chunks.
 
If any one knows the other causes and solutions for this Error, please reply.
 
Here is my code...Please find.
#ifndef CLIENTREQ_H_
#define CLIENTREQ_H_

#include <bb/cascades/AbstractPane>
#include <QtNetwork/qtcpsocket.h>
#include <bb/cascades/Application>
#include <bb/data/JsonDataAccess>
#include <bb/cascades/Page>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/WebView>
#include <QLocale>
#include<qstring.h>
#include <QTranslator>
#include <Qt/qdeclarativedebug.h>
#include <bb/cascades/XmlDataModel>
#include <QtCore/qthread.h>
#include <bb/cascades/Container>
#include <bb/cascades/GroupDataModel>
#include <bb/cascades/ListView>
#include <bb/cascades/NavigationPane>
#include<QtDeclarative/qdeclarativeproperty.h>
#include <Qt/qdeclarativedebug.h>
#include <QtCore/qdebug.h>
#include <bb/cascades/JavaScriptWorld>
#include <QByteArray>
#include <bb/cascades/Label>
#include <QtCore/QList>
#include <unistd.h>
#include <stdlib.h>
#include "SocketBase.h"
#include "DatabaseOperations.h"
#include "applicationui.hpp"
#include <bb/data/JsonDataAccess>
using namespace bb::data;

class ClientReq: public QThread,SocketBase {

public:
	ClientReq(const QString &ipAddr, const ushort port) :
		SocketBase(ipAddr, port) {
		mDone = false;
		//connect(this, SIGNAL(disconnected()), SLOT(ReconnectToHost()));
	}

	//void ReconnectToHost(){this.connectToHost(ipAddr, port);}
	void startThread(ApplicationUI *_app);
	void stopThread();
	bool isDone();
	Identity getIdentity() {
		return CLIENT;
	}
	int m_symbolHint;
	int m_dropHint;
	// QString dropText;
	//static QString reqText ;
	static QMap<int, QString>  jsonMap;
	static QMap<int, QString>  getJsonMap();
	 QString reqText;
	 QList<QString> list;
public Q_SLOTS:
	    void finishDialog();

protected:
	void run();
	void setDone(const bool newVal);

	//sends login data(phno,device_id) and Symbols Req

	void readDataFromSocket();// reads corresponding Symbols Req'ted data from socket
public:
	 QList<QString> getDatafromClientReq();
	 QList<QString>  getFeed();
	void dropSymbolReq();
	bool writeOnlyMethod( bool isWrite);
	bool dropOnlyMethod( bool isDrop);
	void clearSymbolsList();
	void reading();
	void openTcpConnection();
    bool isNetworkAvailable();
    bool isTimeUp();
    void appExit();


 //  void writeToLog(QString data);
   // QString getImeiNum();

private:
	static const unsigned int CONNECT_TIME_OUT = 5 * 1000; // 5 seconds
	static const char *mStrings[];
	static const uint mNumStrings;
	bool mDone;
	bool writeOnly;
	bool dropOnlyOnce;
    //QTcpSocket socket;
	bool  isSocketConOpen;
	bool loginServer(QTcpSocket& socket, QHostAddress hostAddr,
			bool loginSuccess);



};
#endif /* CLIENTREQ_H_ */

 

#include "ClientReq.h"
#include "DatabaseOperations.h"
#include <bb/data/JsonDataAccess>
#include <QByteArray>
#include "Helper.h";
#include <QThread>
#include <QtNetwork/qnetworkconfiguration.h>
#include <bb/device/HardwareInfo.hpp>
#include "SubcriptDB.h"

using namespace bb::data;
using namespace bb::system;
using namespace bb::device;
int _5Mins=300;
/* Implementing Client Side Class member functions */
ApplicationUI *apps;
// Symbols List read from server
void ClientReq::setDone(const bool newVal)
{
QMutexLocker lock(&mMutex);
mDone = newVal;
}
bool ClientReq::isDone()
{
QMutexLocker lock(&mMutex);//
return mDone;
}
void ClientReq::finishDialog(){
}
bool ClientReq::loginServer(QTcpSocket& socket, QHostAddress hostAddr,
bool loginSuccess)
{
if (!isSocketConOpen)
{
socket.connectToHost(hostAddr, mPort);
if (socket.waitForConnected(CONNECT_TIME_OUT))
{
QHostAddress hostAddr = socket.localAddress();
QString addr = "";
if (hostAddr != QHostAddress::Null)
{
addr = hostAddr.toString();
}
if (addr.length() > 0)
{
qDebug() << addr;
qDebug() << socket.localPort();
}
Helper::writeToLog("CONNECT_TIME_OUT \n");
}
isSocketConOpen = true;

QString dev_id=Helper::device_pin;
QString conData = "Login:"+dev_id+","+dev_id+","+dev_id+","+Helper::userType+",blackberry";

qDebug()<<"Connection Data"<<conData;
QString data=writeLine(&socket, conData);
if(data == "NO INTERNET"){
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
Helper::writeToLog("Socket Connection String::: \n"+conData);
QString status = "";
//printf("Login Status::: %s \n",status.toAscii().data());
QString longedText = "LoginStatus:1";
int exitCount=0;
while (true)
{
status = readLine(&socket, "req");
if (status == "NO INTERNET") {
//qDebug()<<echoedLine<<"vachindi";
apps->alert("please try again, if failed again restart the application");
//status = "";
}
Helper::writeToLog("Login Status:::" + status);
if (status == longedText) {
qDebug() << " LoginStatus :::: " + status;
break;
}
}
if (status == longedText && status !="NO INTERNET")
{
QByteArray allJsonByteArray = "";
QString data1 = writeLine(&socket, "RequestSymbols:All");
if (data1 == "NO INTERNET") {
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
Helper::writeToLog("Request All::: \n RequestSymbols:All");
printf("RequestSymbols:All sent \n ");
QString qBytes = "-1";
while (qBytes == "-1") {
qBytes = readLine(&socket, "all");
if(qBytes!="NO INTERNET")
Helper::requestAll = qBytes;
}
Helper::writeToLog("RequestAll:::" + Helper::requestAll);
QString data2 = writeLine(&socket, Helper::reqText);
if (data2 == "NO INTERNET") {
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
loginSuccess = true;
Helper::isLogin = true;
}
else
{
qDebug() << status;
}
}
return loginSuccess;
}
/**
Note that the QTcpSocket object must be in the run thread. It cannot
be a class variable.
*/
void ClientReq::run()
{
try
{
QTcpSocket socket;
QHostAddress hostAddr(mIP);
bool loginSuccess = false;
QString echoedLine;
long ix = 0;
loginSuccess = loginServer(socket, hostAddr, loginSuccess);
bool isReqRecieved;
while (true)
{
if (loginSuccess) {
try {
if (Helper::reqText.length() > 0) {
qDebug() << "Client - " + Helper::reqText;
delay(1000);
QString data = writeLine(&socket, Helper::reqText);
qDebug()<<"SocketBase::Write line"<<data;
if (data == "NO INTERNET") {

apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
Helper::writeToLog(
" ClientRun::run Request Symbols::: \n" + Helper::reqText);
Helper::tailrequest = Helper::reqText;

if(data != "NO INTERNET")
Helper::reqText = "";
}

echoedLine = readLine(&socket, "req");

if (echoedLine == "NO INTERNET") {
//qDebug()<<echoedLine<<"vachindi";

apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
//echoedLine="";
}

Helper::writeToLog("Response Symbols:::\n" + echoedLine);
if (echoedLine == "-1") {
loginSuccess = false;
isSocketConOpen = false;
loginSuccess = loginServer(socket, hostAddr,
loginSuccess);
if (loginSuccess) {
QString data = writeLine(&socket,Helper::tailrequest);
qDebug()<<"SocketBase::Write line"<<data;
if (data == "NO INTERNET") {
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
}
break;
}
QString longedText = "LoginStatus:1";
if (!echoedLine.contains(longedText) && echoedLine!="NO INTERNET")
Helper::feedlist.insert(Helper::counter, echoedLine);
Helper::counter++;
//}
} catch (std::exception &e) {
qDebug() << e.what();
qDebug() << "Unknown Exception Occurred in Client Req\n";
}
}
QThread::msleep(10);
} // Infinite while
qDebug() << "Thread Ended\n";
} catch (...)
{
qDebug() << "Unknown Exception Occurred in Client Req\n";
Helper::writeToLog("Unknown Exception Occurred in Client Req\n");
}
} // run
void ClientReq::dropSymbolReq()
{
QTcpSocket socket;
while (socket.state() == QAbstractSocket::ConnectedState && dropOnlyOnce)
{
//sending dropQuery to server
QString dropQuery;
QString data;
switch (m_dropHint) {
case 1:
// preparing Req Query
dropQuery = "DropUpdate:1010,1020,1030,1040,1050;";
//writing dropQuery to Server socket
data = writeLine(&socket, dropQuery);
qDebug()<<"SocketBase::Write line"<<data;
if (data == "NO INTERNET") {
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
printf(" Tadawul Symbols Dropped");
 
break;
case 2:
// preparing Req Query
dropQuery = "DropUpdate:2,3,4,5,6;";
//writing dropQuery to Server socket
data = writeLine(&socket, dropQuery);
qDebug()<<"SocketBase::Write line"<<data;
if (data == "NO INTERNET") {
apps->alert("please try again, if failed again restart the application");
QCoreApplication::processEvents();
}
printf(" Forex Symbols Dropped");
break;
default:
break;
}
//}
} // while
}
void ClientReq::startThread(ApplicationUI *_app)
{
apps = _app;
setRunThread(true);
start();
}
void ClientReq::stopThread()
{
//setRunThread(false); make
}
QList<QString> ClientReq::getFeed()
{
QList<QString> ClientList;
if (Helper::feedlist.size() > 0)
{
ClientList = Helper::feedlist;
Helper::feedlist.clear();
Helper::counter = 0;
//qDebug()<<"Helper::feedlist"<<Helper::feedlist.size();
}
//qDebug()<<"Helper::feedlist"<<ClientList.size();
return ClientList;
}
QList<QString> ClientReq::getDatafromClientReq()
{
QList<QString> ClientList;
if (Helper::feedlist.size() > 0)
{
ClientList = Helper::feedlist;
}
return ClientList;
}
void ClientReq::clearSymbolsList()
{
Helper::feedlist.clear();
Helper::counter = 0;
}
bool ClientReq::isNetworkAvailable()
{
bool isFound=false;
QNetworkConfigurationManager netMgr;
QList<QNetworkConfiguration> mNetList = netMgr.allConfigurations(QNetworkConfiguration::Active);
if (mNetList.count() > 0)
{
if (netMgr.isOnline())
{
isFound= true;
}
}
//qDebug()<<"NetworkState:::"<<isFound;
return isFound;
}
bool ClientReq::isTimeUp() {
bool isUp = false;
int currentTime = QDateTime::currentMSecsSinceEpoch() / 1000;
//qDebug()<<"current time stamp :::"<<currentTime;
QString time = DatabaseOperations::getTimeStamp("timeStamp");
//qDebug()<<":::**************:::"<<time;
if (time != "") {
bool ok;
int savedTime = time.toInt(&ok, 10);
//qDebug()<<"saved time stamp :::"<<currentTime;
if (currentTime >= savedTime) {
isUp = true;
bool isDeleted = DatabaseOperations::deleteRecord("timeStamp");
if (isDeleted)
qDebug() << ":::data erased:::";
qDebug() << "5 mins Over and making new req for symbols";
} else {
// qDebug() << "5 mins are not Over and displaying the same data";
}
} else {
qDebug() << ":::**************:::";
isUp = true; // to enter into loop
}
return isUp;
}
void ClientReq::appExit() {
//writeLine(&socket, "Exit:1;"); //writing Exit Request to Server;
qDebug() << ":::Exit Request Sent:::";
}
 

 

/*
 * SocketBase.h
 *
 *  Created on: Aug 7, 2013
 *      Author: user
 */

#include <QtNetwork/qtcpsocket.h>
#include <QtCore/qthread.h>
#include <QtCore/qdebug.h>
#include <bb/cascades/JavaScriptWorld>
#include <bb/cascades/Label>
#include <QtCore/QList>
#include <unistd.h>
#include <stdlib.h>
#include<QList>
#include <bb/system/SystemDialog>
#include <bb/cascades/Application>
#include "PushDAO.hpp"

using namespace bb::system;

#ifndef SOCKETBASE_H_
#define SOCKETBASE_H_

//QString ip;
//QString portno;

class SocketBase: public QObject{
	Q_OBJECT
public:
	SocketBase(const QString &ipAddr, const ushort port) :
			mIP(ipAddr), mPort(port) {
		mRunThread = false;
		//ip=ipAddr;
		//portno=port;
		//connect(this, SIGNAL(disconnected()), SLOT(ReconnectToHost()));
	}
	//void ReconnectToHost(){this.connectToHost(ip, portno);}
	enum Identity {
		BAD_IDENTITY, SERVER, CLIENT
	};
	//virtual void startThread() = 0;
	virtual void stopThread() = 0;
	virtual Identity getIdentity() = 0;
	Q_INVOKABLE void showDialog(int id);
	Q_INVOKABLE void AddAlerts(int pos,QString langText);
	void exitApp();
	void onOkAlert(const QString &message);

	 public slots:
	 	 void onAPPFinished();
	 	 void onDialogFinished(bb::system::SystemUiResult::Type);

protected:
	QMutex mMutex;
	const QString mIP;
	const ushort mPort;
	PushDAO *pushStatusDao;

	void setRunThread(bool newVal);
	bool getRunThread();
	void run();
	QString readLine(QTcpSocket *socket,QString param);
	QList<QByteArray> readAllSymb(QTcpSocket *socket);
	void showToast(QString message);
	int waitForInput(QTcpSocket *socket);
	void requestAll(QTcpSocket *socket);
	QString  writeLine(QTcpSocket *client, const QString &line);
	QString remaining;
private:
	bool mRunThread;
};

#endif /* SOCKETBASE_H_ */

 

#include "SocketBase.h"
#include "Helper.h"
#include "AlertsList.h"
#include <bb/cascades/Application>
#include <QtNetwork/qtcpsocket.h>
#include <QtCore/qthread.h>
#include <QtCore/qdebug.h>
#include <bb/cascades/JavaScriptWorld>
#include <bb/cascades/Label>
#include <QtCore/QList>
#include <unistd.h>
#include <stdlib.h>
#include<QList>
#include <QByteArray>
#include <bb/data/JsonDataAccess>
#include <unistd.h>
#include "DatabaseOperations.h"
#include "applicationui.hpp"
#include <bb/system/SystemToast>
#include <bb/system/SystemUiPosition>
#include <bb/system/SystemListDialog>
#include <QObject>
#include <QtSql/QtSql>
#include <QDebug>
#include <QLocale>
#include <QByteArray>
using namespace bb::cascades;
using namespace bb::data;
using namespace bb::system;
SystemDialog *dialog;
SystemDialog *dialog2;
SystemDialog *dialogExit2;
int dCount=0;
int dCount2=0;
/* SocketBase Class member functions Implementation */
void SocketBase::setRunThread(bool newVal)
{
	QMutexLocker lock(&mMutex);
	mRunThread = newVal;
}

bool SocketBase::getRunThread()
{
	QMutexLocker lock(&mMutex);
	return mRunThread;
}

int SocketBase::waitForInput(QTcpSocket *socket)
{
	int bytesAvail = -1;
			&& bytesAvail < 0)
	{
			if (socket->waitForReadyRead(100))
		{
			bytesAvail = socket->bytesAvailable();
		}
		else
		{
		
			if (Helper::reqText.length() > 0)
			{
				return -1;
			}
			delay(10);
		}
	}
	if(socket->state() != QAbstractSocket::ConnectedState){
	}
	return bytesAvail;
}

QString SocketBase::readLine(QTcpSocket *socket,QString param)
{
	//qDebug()<<"SocketBase::readLine() call ok";

	if (socket->state() != QAbstractSocket::ConnectedState) {
		//qDebug()<<"Socket not connected in SocketBase::Read Line";
		Helper::writeToLog(" Socket not connected in SocketBase::Read Line");
		//socket->reset();
		return "NO INTERNET";
	}
	QString line="";
	if(param=="req"){

	//QStringList list;

	QString add = "";
	QByteArray tempBA = "";
	int bytesAvail = waitForInput(socket);

	if (bytesAvail > 0)
	{
			bool skipremaining = false;

			tempBA = socket->readAll();

			
			if (tempBA.length() > 0) {

				QString ba = remaining + QString(tempBA);
				QStringList testList = ba.split('}');
				JsonDataAccess jda;
				for (int i = 0; i < testList.size(); i++) {

				QString temp;
                 if(testList.at(i)!="]"){
				  temp = "[" + testList.at(i) + "}]";
//				 
                 }


					QVariantList data = jda.loadFromBuffer(temp).toList();

					//qDebug()<<"data size:::::"<<data.size();
					if (!jda.hasError()) {
						line += testList.at(i) + "},";
					//	qDebug()<<"json"<<testList.at(i) + "},";
						//qDebug()<<"\n json ok";
					} else {
						//qDebug()<<"\n json error";
						// qDebug() << testList.at(i);
						if (testList.at(i).contains("AlertStatus")) {
							bool isBool;

							QString str = testList.at(i);
							qDebug() << str.split("AlertStatus:");
							QString temp =testList.at(i).split("AlertStatus:").at(1);
							QString temp1 = temp.split(';').at(0);
							QString temp2 = temp1.split(',').at(0);
							QString temp3 = temp1.split(',').at(1);



							int serverid = temp2.toInt(&isBool);// EURUSD is reached : 1.444564
							DatabaseOperations::updateAlertServerId(temp3,serverid);
							//showDialog(serverid);
							skipremaining = true;
						}
						if (testList.at(i).contains("AlertExecuted")) {
							bool isBool;
							QString str = testList.at(i);
							// qDebug() << str.split("AlertExecuted:");
							QString temp = testList.at(i).split(
									"AlertExecuted:").at(1);
							QString temp1 = temp.split(';').at(0);
							int serverid = temp1.toInt(&isBool);
							showDialog(serverid);
							skipremaining = true;
//					line+=testList.at(i);
						}

						if (testList.at(i) == "LoginStatus:1") {
							return testList.at(i);
						}
						if (!skipremaining && i + 1 == testList.size()) {
							remaining = testList.at(i);
						}
					}
				}
			}

//	
	}else{
		qDebug()<<"\n SocketBase:: nodata";
	}
	}else if(param=="all"){
		        QByteArray qLine = "";
				QList<QString> listAll;
				int bytesAvail = waitForInput(socket);

				if (bytesAvail > 0) {
					//int symbolCount = 0;
					int cnt = 0;
					bool endOfLine = false;
					bool endOfStream = false;

					/* line.append(socket->readAll());
					 line.append(',');
					 endOfLine = true;*/
					int count=0;
					while (true) {

					


						char ch;
						QString byte;
						//int bytesRead = socket->read(&ch, sizeof(ch));
						delay(1000);
						bytesAvail = socket->bytesAvailable();
						if (bytesAvail > 0) {
							byte = socket->readAll();
							listAll.append(byte);

							qDebug() << "::: Json data  &colon;::" << byte;
						} else {
							int currentTime = QDateTime::currentMSecsSinceEpoch();
							//qDebug()<<"::: Json data  bytes avail:::"<<bytesAvail;

							writeLine(socket, "-");
							QString log = "::: Sending the Request Again:::" + QString::number(currentTime,10)  ;
							qDebug() << log;
							count++;
						}

				if (byte.contains("]")) {
					QString log = "===============" + QString::number(count,10)  ;
					qDebug() << log;
					break;
				}



					}




					//QString testJson;
					for(int i=0;i<listAll.size();i++){
						line+=listAll.at(i);
					}
					qDebug()<<"Total Json:::"<<line;
					//exit(1);
				}else{
					//printf(" ::: No data found in SocketBase::readLine ::: \n" );
					line="-1";
				}
			   // printf("******** Inside readAllSymb ******* %s\n", line.toAscii().data() );
						//return listAll;
	}
	//printf(" Socket Data &colon;:: %s\n", line.toAscii().data() );

	return line;
}
void SocketBase::showDialog(int id)
{
	Helper::isAlertExec=true;
	bool ok;
	QList<QVariantMap> list = DatabaseOperations::read_Alert_Records_serverid(id);
for(int i=0;i<list.size();i++)
	qDebug()<<"alertssssssss"<<list.at(i);

	 QMap<int, QString> map = Helper::getJsonMap();

	QString symb= map[ list.at(0)["AlertSymb"].toInt(&ok)];

	QString alertText;;
	
		alertText =symb + " "+tr("is reached:")+list.at(0)["AlertPrice"].toString();
	//else if(Helper::lang_settings=="Arabic")
    	//alertText =tr("is reached:")+symb+list.at(0)["AlertPrice"].toString()+" ";


	SystemDialog *dialog; // SystemDialog uses the BB10 native dialog.
	dialog = new SystemDialog(tr("OK")); // New dialog with on 'Ok' button, no 'Cancel' button
	dialog->setTitle(tr("Alert Executed")); // set a title for the message
	dialog->setBody(alertText); // set the message itself
	dialog->setDismissAutomatically(true); // Hides the dialog when a button is pressed.

	// Setup slot to mark the dialog for deletion in the next event loop after the dialog has been accepted.
	connect(dialog, SIGNAL(finished(bb::system::SystemUiResult::Type)), dialog, SLOT(onDialogFinished(bb::system::SystemUiResult::Type type)));
	dialog->show();
	QString sid = list.at(0)["Id"].toString();
	// qDebug() << sid;
	DatabaseOperations::deleteOf(sid.toInt(&ok));

	qDebug()<<"Alert Excecuted";
	
}
void SocketBase::onAPPFinished()
{
	qDebug() << " GOING TO DIE ";
	bb::Application::exit(0);
}
//void SocketBase::onDialogFinished(bb::system::SystemUiResult::Type type)
//{
//
//
//}
QString  SocketBase::writeLine(QTcpSocket *socket, const QString &line)
{
	QString net;
	if (socket->state() != QAbstractSocket::ConnectedState)
	{
		qDebug()<<"\n Socket not connected in SocketBase::writeLine";
		Helper::writeToLog(" Socket not connected in SocketBase::writeLine");
		bb::Application *app;
		 // SystemDialog uses the BB10 native dialog.

		 net="NO INTERNET";

	}
	if (line.length() > 0)
	{
		socket->write(line.toAscii());
		if (!socket->waitForBytesWritten())
		{
			if (getIdentity() == SERVER)
			{
				printf("Server - ");
			}
			else if (getIdentity() == CLIENT)
			{
				printf("Client - ");
			}
			else
			{
				printf("Unknown identity - ");
			}
			printf("writeLine: the write to the socket failed\n");
		}
		 net="";

	}
	 return net;

}
QList<QByteArray> SocketBase::readAllSymb(QTcpSocket *socket)
{
	QByteArray line = "";
		QList<QByteArray> listAll;
		int bytesAvail = waitForInput(socket);

		if (bytesAvail > 0) {
			//int symbolCount = 0;
			int cnt = 0;
			bool endOfLine = false;
			bool endOfStream = false;

			/* line.append(socket->readAll());
			 line.append(',');
			 endOfLine = true;*/
			while (true) {
				char ch;
				int bytesRead = socket->read(&ch, sizeof(ch));
				if (bytesRead == sizeof(ch)) {
					cnt++;
					line.append(ch);
					qDebug()<<ch;
					printf(" ::: Char found  ::: \n" );
					if (ch =='}'){
						listAll.append(line);
						printf(" finish line read::: %s\n", QString(line).toAscii().data() );
						endOfLine = true;
					}else if(ch==']'){
						printf(" ::: Loop Breaked   ::: \n" );
						break;
					}
				} else {
					endOfStream = true;
					//printf(" ::: No data found  ::: %s\n" );
				}
			}
		}else{
			printf(" ::: No data found in SocketBase::readAllSymb ::: \n" );
		}
	   // printf("******** Inside readAllSymb ******* %s\n", line.toAscii().data());
		return listAll;
}
void SocketBase::showToast(QString message)
{
	SystemToast *toast = new SystemToast(this);
	toast->setBody(message);
	toast->setPosition(SystemUiPosition::MiddleCenter);
	toast->show();
}
void SocketBase::requestAll(QTcpSocket *socket){

	printf("******** Inside requestAll *******");
	if (socket->state() != QAbstractSocket::ConnectedState) {
	
	}
	QString line;
	//QStringList list;
	QString add = "";
	QByteArray tempBA = "";
	int bytesAvail = waitForInput(socket);
	printf("******** Inside requestAll Bytes Available::: ******* %d",bytesAvail);
	if (bytesAvail > 0)
	{
		//bool skipremaining = false;

		tempBA = socket->readAll();

		printf("******** Inside readAllSymb ******* %s\n", QString(tempBA).toAscii().data());
		qDebug()<<"requestAll:::"<<tempBA;

	

	}
	//printf(" Socket Data &colon;:: %s\n", line.toAscii().data() );
}
void SocketBase::exitApp()
{
	//bb::Application::instance()->requestExit();
	pushStatusDao->removeAll();
	//delay(2000);
	bb::Application::exit(1);

}
void SocketBase::onOkAlert(const QString &message)
{
	// SystemDialog uses the BB10 native dialog.

	dialogExit2 = new SystemDialog(tr("OK"), 0); // New dialog with on 'Ok' button, no 'Cancel' button
	dialogExit2->setTitle(tr("Alert")); // set a title for the message
	dialogExit2->setBody(message); // set the message itself
	dialogExit2->setDismissAutomatically(true); // Hides the dialog when a button is pressed.

	// Setup slot to mark the dialog for deletion in the next event loop after the dialog has been accepted.
	 bool success = connect(dialogExit2,
				            SIGNAL(finished(bb::system::SystemUiResult::Type)),
				            this,
				            SLOT(onDialogFinished(bb::system::SystemUiResult::Type)));
	 if(success)
	 dialogExit2->show();
}
void SocketBase::onDialogFinished(bb::system::SystemUiResult::Type){
	qDebug()<<"SocketBase::dialog->result():::"<<dialogExit2->result();
	if(dialogExit2->result()==2)
	{
		qDebug()<<"::: Terminate App :::";
		//exitApp();
	}
}
void SocketBase::AddAlerts(int tabPos ,QString langText)
{

	Page *alertsPage;
	// AddOrDeleteSymbols *ref= new  AddOrDeleteSymbols ();
	AlertsList *obj = new AlertsList();

	NavigationPane *cumTab;

			obj->UpdateValue(alertsPage, "alerts", cumTab);

}
 and here I am connecting to server like,
const QString IP= "80.103.111.2";
const ushort port = 9011;
ClientReq client(IP, port);

 In the above code, I am getting this error exactly at

 

if (socket->state() != QAbstractSocket::ConnectedState) {
		//qDebug()<<"Socket not connected in SocketBase::Read Line";
		qDebug()<<"***********Socket Error************ socketBAse::Readline"<<socket->errorString();
		Helper::writeToLog("***********Socket Error************ socketBAse::Readline"+socket->errorString());

}
socket->errorString();// returns "Software caused connection abort Error "
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Software caused connection abort Error (Network Error)

I think it probably *is* caused by case 1. Most likely a network entity between the BlackBerry device and the server, and including the server process you are connecting to, is closing the connection for some reason. Just because you were able to read some data, it does not follow that the server (or an intermediate node like a proxy or gateway) will not close the connection.

 

If you have access to the server you are connecting to you can perhaps do some investigation at that end using tools like Wireshark and tcpdump.

 

Does the issue happen when you are using wi-fi? Or only when using a carrier network?

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Software caused connection abort Error (Network Error)

p.s. can you post your console output and slog2info output lines from either side of this error arising please? Thanks.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
New Developer
Posts: 104
Registered: ‎09-25-2013
My Device: BB 10
My Carrier: BB 10

Re: Software caused connection abort Error (Network Error)

Please find the log here...

SocketBase::Write line "" 

 SocketBase::readLine() nodata 

***********Socket Error************ socketBAse::Readline "Software caused connection abort" 


***********Socket Error************ socketBAse::Readline "Software caused connection abort" 

***********Socket Error************ socketBAse::Readline "Software caused connection abort" 

 Thanks!!!

New Developer
Posts: 104
Registered: ‎09-25-2013
My Device: BB 10
My Carrier: BB 10

Re: Software caused connection abort Error (Network Error)

For your Information,  I find one more cause for termination on my research. i.e,

 

A connection abort was caused internal to your host machine. The software caused
a connection abort because there is no space on the socket’s queue and the socket
 cannot receive further connections.