本文介绍了WSAECONNABORTED 1053错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在编写一个程序来获取用户的浏览器数据包(127.0.0.1:8000)并将其从我的程序发送到目的地,并从目的地接收数据将其发送回用户的浏览器。
当我执行程序时出现错误WSAECONNABORTED。
我的代码:
Hello everyone,
I'm writing a program to get user's browser packet on (127.0.0.1:8000) and send it from my program to the destination, and receive data from the destination and send it back to the user's browser.
When I execute my program the error "WSAECONNABORTED" is occured.
My code:
#include "stdafx.h"
#pragma comment(lib, "ws2_32")
using namespace HttpSockets;
using namespace std;
using namespace Screen;
using namespace Exceptions;
struct ClientSockets {
Socket S; //I have created a special class to handle all win32 socket operations.
Socket C;
};
string Receiving(Socket);
DWORD WINAPI ReceiveFromClient(LPVOID lpParam);
DWORD WINAPI ReceiveFromServer(LPVOID lpParam);
HANDLE thread;
int main(int argc, char* argv[])
{
PrintScreen Printer;
try {
Socket SocketServer;
EndPoint EP;
EP.Create("0.0.0.0", 8000);
SocketServer.Bind(EP);
SocketServer.Listen(10);
int x = 0;
while(true) {
ClientSockets Client;
Socket S = SocketServer.Accept();
Socket C;
C.Connect("198.252.206.140", 80);
Client.S = S;
Client.C = C;
CreateThread(NULL, 0, ReceiveFromClient, &Client, 0, NULL);
CreateThread(NULL, 0, ReceiveFromServer, &Client, 0, NULL);
}
}
catch(Exception &ex) {
Printer.Print("\n");
Printer.Print(ex.what(), Red | Intensity);
Printer.Print("\n");
}
system("pause");
return 0;
}
DWORD WINAPI ReceiveFromServer(LPVOID lpParam)
{
ClientSockets *Client = (ClientSockets*)lpParam;
Socket S = Client->S;
Socket C = Client->C;
PrintScreen Printer;
try {
while(true) {
string Buffer = Receiving(C);
if(Buffer != "") {
S.Send((char*)Buffer.c_str());
Printer.Print(Buffer);
}
}
}
catch(Exception &ex) {
Printer.Print("\n");
Printer.Print("ReceiveFromServer: [");
Printer.Print(ex.what(), Red | Intensity);
Printer.Print("]");
Printer.Print("\n");
}
return 0;
}
DWORD WINAPI ReceiveFromClient( LPVOID lpParam )
{
ClientSockets *Client = (ClientSockets*)lpParam;
Socket S = Client->S;
Socket C = Client->C;
PrintScreen Printer;
try {
while(true) {
char buffer[65535];
S.Receive(buffer);
string data;
data.append(buffer);
while(true) {
size_t f = data.find("127.0.0.1:8000");
if(f != string::npos) data.replace(f, string("127.0.0.1:8000").length(), "stackoverflow.com");
else break;
}
C.Send((char*)data.c_str());
}
}
catch(Exception &ex) {
Printer.Print("ReceiveFromClient: [");
Printer.Print(ex.what(), Red | Intensity);
Printer.Print("]");
Printer.Print("\n");
}
return 0;
}
string Receiving(Socket client)
{
string data;
char* Buffer = (char*)malloc(1024);
int Result = client.Receive(Buffer, 1024);
Buffer[Result] = '\0';
if(Result > 0)
{
data.append(Buffer);
}
return data;
}
那么,我的代码有什么问题???
推荐答案
这篇关于WSAECONNABORTED 1053错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!