Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 21:28

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Multithreading

Discussion on Multithreading within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
Multithreading

Hi i have q how i create a multithread socket for this code ?

Code:
#pragma comment(lib,"ws2_32.lib")
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <sstream>
#include "TwojeImie.h"
using namespace std;

std::string decrypt(std::string str,int size);
std::string EncryptLoginPacket(std::string str);
std::string GetPasswordString(std::string str);

void main()
{
WSAData wsa;
WORD Version = MAKEWORD(2,1);
WSAStartup(Version, &wsa);

SOCKET Listen = socket(AF_INET, SOCK_STREAM, 0);
SOCKET Connect = socket(AF_INET, SOCK_STREAM, 0);

SOCKADDR_IN Server;

char ip[14] = "5.211.100.16";
int port = 4001;
Server.sin_addr.s_addr = inet_addr(ip);
Server.sin_family = AF_INET;
Server.sin_port = htons(port);

bind(Listen, (SOCKADDR*)&Server, sizeof(Server));

listen(Listen, 1);
int size = sizeof(Server);

std::cout << "--------------------------------------------------------------------------------"
<< "" 
<< " Server connected." << std::endl
<< " Host: " << ip << " : " << port << std::endl
<< "--------------------------------------------------------------------------------" << std::endl;






for(;;){
if(Connect = accept(Listen, (SOCKADDR*)&Server, &size)){
std::cout << "Connection accepted from: " << inet_ntoa(Server.sin_addr) << std::endl;
int sizes;
char recvbuf[512];
sizes = recv(Connect,recvbuf,512,0);
std::string Packet;
for(int i =0; i < sizes;i++){Packet += (int)recvbuf[i] - 0xf ^0xc3;}
std::cout << Packet << std::endl;

std::string fail = "NsTest 7998 5.211.100.16:1337:0:1.0.NosPriv -1:-1:-1";
send(Connect,EncryptLoginPacket(fail).c_str(), EncryptLoginPacket(fail).length() +1,0);



}

}

WSACleanup();
std::cin.get();




std::string fail = "Złe ID lub Hasło";
send(Connect,fail.c_str(),fail.size(),0);


}


std::string decrypt(std::string str,int size)
{
    std::string decrypted_string;

    for (int i = 0; i < size; i++) { decrypted_string += str[i] - 0xF ^ 0xC3; }

    return decrypted_string;
}

std::string EncryptLoginPacket(std::string str)
{
	std::string encrypted_string;

	for (int i = 0; i < str.length(); i++) { encrypted_string += str[i] + 0xF; }

	return encrypted_string += 0x19;
}

std::string GetPasswordString(std::string str)
{
	std::string decrypted_string;
	int count = 1;
	int convert;

	if (str.length() %2 == 0)
	{
		str.erase(0, 3);
	} else
	{
		str.erase(0, 4);
	}

	for (int i = 0; i < str.length(); i+=2)
	{
		decrypted_string += str[i];

		if (count %2 == 0)
		{
			decrypted_string += ' ';
		}
		count++;
	}

	std::stringstream ss(decrypted_string);
	decrypted_string.clear();

	while (ss >> std::hex >> convert)
	{
		decrypted_string.push_back(convert);
	}

	return decrypted_string;
}
??
szymek111 is offline  
Old 10/22/2012, 18:38   #2
 
elite*gold: 0
Join Date: Nov 2007
Posts: 62
Received Thanks: 17


Hope this helps.
Demon-777 is offline  
Old 10/29/2012, 23:47   #3
 
elite*gold: 0
Join Date: Oct 2012
Posts: 6
Received Thanks: 2
Well what part do you want to be threaded?
hound1 is offline  
Old 10/30/2012, 08:19   #4
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
all?For accepting connections :|
szymek111 is offline  
Old 10/30/2012, 11:40   #5
 
Tyrar's Avatar
 
elite*gold: 0
Join Date: Oct 2008
Posts: 1,637
Received Thanks: 1,119
magic word: "select"
Tyrar is offline  
Old 10/30/2012, 13:19   #6
 
.SkyneT.'s Avatar
 
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
Did you even try it ?
I don't see anything related to multithreading
in your piece of code.

And don't forget to use the [CODE] - tags.
.SkyneT. is offline  
Old 11/17/2012, 01:03   #7




 
bloodx's Avatar
 
elite*gold: 55
Join Date: Mar 2006
Posts: 4,582
Received Thanks: 1,537
You can learn Multithreaded without Copy & Paste!
bloodx is offline  
Old 11/17/2012, 11:27   #8
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
Guys gave me the tutorial please .
szymek111 is offline  
Old 11/17/2012, 12:43   #9




 
bloodx's Avatar
 
elite*gold: 55
Join Date: Mar 2006
Posts: 4,582
Received Thanks: 1,537
Giv me 100€ ok or no?
bloodx is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
Multithreading
10/08/2012 - C/C++ - 25 Replies
Guten Tag Leute, Ich befasse mich seid ca 2 monaten immer mal wd mit c++ und probiere mich dran einfache Programme zu schreiben . Nun aber wollte ich mich mal am multithreading versuchen da ich eine Schleife programmieren will die solange läuft bis der Benutzer einen button drückt oder Bei der konsole per eingabe die schleife stoppt. Mir wurde gesagt ich soll eine globale Variable definieren was ich getan habe und dann die schleife in einen Threat packen soll .Mein Problem ist nun aber das...
Vb.Net String für multithreading?
11/24/2011 - General Coding - 13 Replies
Hey, ich habe einen socket server mit multithreading und setze nach Class ein paar sachen wie z.b. Dim paketcommand2 as string = vbnullstring ich greife mit einem multithreading thread darauf zu und dann kommt immer Das ActiveX-Steuerelement 248dd896-bb45-11cf-9abc-0080c7e7b78d kann nicht instanziiert werden, da der aktuelle Thread kein Singlethread-Apartment ist. wie kann ich das ändern ohne es in jede Sub reinzuschreiben? da ich dort auch sachen gesetzt habe die von mehreren subs...
[C++] D3D Multithreading
08/24/2011 - C/C++ - 0 Replies
Sry kann closed werde. MfG
Multithreading
03/17/2010 - AutoIt - 16 Replies
$handle = DllCallbackRegister("_Threadstart"," ;int","ptr") $handlr = DllCallbackRegister("_Threadstard"," ;int","ptr") $dll = DllStructCreate("Char;int") DllStructSetData($dll,1,"hi") DllStructSetData($dll,2,1234) $ret = DllCall("kernel32.dll","hwnd", "CreateThread","ptr",0,"d word",0,"long",DllCallbackGetPtr($h andle),"ptr",DllStructGetPtr($dll)," ;long",0,"int*",0)...
C++ Multithreading + Klassen
01/16/2010 - C/C++ - 8 Replies
Mein Problem ist es , dass ich eine Klasse habe (nehmen wir als Beispiel Auto) und eine Funktion (Beispiel : BremswegBerechnen) habe , die aber in einem extra Thread laufen soll . Also so in etwa : . . . int main() { CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)BM W.BremswegBerechnen, 0, 0, 0);



All times are GMT +2. The time now is 21:28.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.