Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


winsock question
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Oct 11, 2007 5:18 pm    Post subject: winsock question Reply with quote

I don't get this code. How are you receiving "hello" if buf doesn't equal "hello"?

Code:


#include <windows.h> //Required for socket init
#include <iostream>
int main(){
char buf[256];
WSAData wsdata; //Declare WSAData
WORD wsver=MAKEWORD(2, 0); //We want Winsock 2.0
int nret=WSAStartup(wsver, &wsdata); //Pass version 2.0 and pointer to implement
if(nret != 0){ //Init failed
/*A successful return value should be 0 */
std::cout<<"Startup failed, error code: "<<WSAGetLastError(); //Returns error code
WSACleanup(); //Cleanup Winsock library
return -1;
}
std::cout<<"Init success\n";
SOCKET kSock=socket(AF_INET, SOCK_STREAM, 0);
if(kSock == INVALID_SOCKET){
std::cout<<"Socket init failed";
return -1;
}
std::cout<<"Socket initialized\n";
sockaddr_in sin;
sin.sin_port=htons(808); //Connect to port 80
sin.sin_addr.s_addr=inet_addr("127.0.0.1"); //Connect to localhost
sin.sin_family=AF_INET;
if(connect(kSock,(sockaddr*)&sin, sizeof(sin)) == SOCKET_ERROR){ //Check the condition
std::cout<<"Connect failed, error: "<<WSAGetLastError(); //Returns error code
WSACleanup(); //Cleanup the library
return -1;
}
std::cout<<"Connection successful!\n";
recv(kSock, buf, sizeof(buf), 0); //Receive "Hello" from server
std::cout << buf;
closesocket(kSock);
return 0;
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Oct 11, 2007 5:25 pm    Post subject: Reply with quote

I will now preform witchcraft to answer your question.

Get this, the data you recieve with the recv() function fills buff[] with the text you send it over the internet! Who would of thought that is what winsock does!

/witchcraft

I bet I blew up your mind.

As a side note, google and MSDN are your friends, you don't need to come here for absolutely every single problem you have. Use the forum as a last resort.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Thu Oct 11, 2007 5:25 pm    Post subject: Reply with quote

"Hello" meaning the first message; a greeting, not literally "Hello" Rolling Eyes
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Oct 11, 2007 5:31 pm    Post subject: Reply with quote

I know appalsap Rolling Eyes and Flyte stop being so sarcastic. And I'm sorry I keep coming to hte forum T.T

Oh btw, so if I were to make a chat program. How would that work. I mean like if someone click the send button send it to the other program and then somehow I have that person start receiving data? But I'm looking it up on google right now.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Thu Oct 11, 2007 5:32 pm    Post subject: Reply with quote

you send them the data with send() and they get it with recv() Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes Rolling Eyes
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Oct 11, 2007 5:44 pm    Post subject: Reply with quote

oib111 wrote:
I know appalsap Rolling Eyes and Flyte stop being so sarcastic. And I'm sorry I keep coming to hte forum T.T

Oh btw, so if I were to make a chat program. How would that work. I mean like if someone click the send button send it to the other program and then somehow I have that person start receiving data? But I'm looking it up on google right now.


You would have 2 threads. They would both loop endlessly, one would check if there is data to receive, receives the data with recv() then places it into a buffer for the program to use. The other thread would be dedicated to sending, though this thread is optional depending on the program (you could have the send() built into the button click).

Also, I will not stop being sarcastic.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Oct 11, 2007 5:47 pm    Post subject: Reply with quote

Lol fine. But can I be an arbitrary jackass? Laughing

Edit:

Btw, I had an idea that I would have to loop. And I would also like to know how to connect to a certain ip. Like instead of putting 127.0.0.1 in the stuct member host could I put their IP address. And how am I supposed to get it.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Oct 11, 2007 6:31 pm    Post subject: Reply with quote

ask them for it?

and yes you can, but they have to have a server open on that port number or you can't connect and you shall phail

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Oct 11, 2007 7:25 pm    Post subject: Reply with quote

T.T Well on aim or msn how do they do it?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Thu Oct 11, 2007 7:46 pm    Post subject: Reply with quote

Those clients connect to a central predefined server with a definite IP. The server then does the job of the middleman to exchange information.
_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Oct 11, 2007 10:32 pm    Post subject: Reply with quote

DeltaFlyer wrote:
Those clients connect to a central predefined server with a definite IP. The server then does the job of the middleman to exchange information.


Not always. If you have to option turned on, you can directly connect to the person and the only purpose the servers have is to maintain login and to receive their IP address in the first place. It basically turns MSN into a small P2P program.
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Fri Oct 12, 2007 6:13 am    Post subject: Reply with quote

Flyte wrote:
You would have 2 threads. They would both loop endlessly, one would check if there is data to receive, receives the data with recv() then places it into a buffer for the program to use. The other thread would be dedicated to sending, though this thread is optional depending on the program (you could have the send() built into the button click).

There are the non-blocking sockets, they won't create any overhead and extra work caused by the threads, but it requires you to make a queue for the data.
Quote:

Use a combination of blocking and non-blocking socket operations. The ability to switch between blocking and non-blocking modes "on the fly" provides a powerful and convenient way to perform socket operations. Note that the warning regarding blocking sockets also applies here.

_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Oct 12, 2007 8:31 am    Post subject: Reply with quote

Ok, aside from sending and receiving data. I don't have a server lol. So how would I get the persons IP and then send and receive from that IP?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Fri Oct 12, 2007 11:39 am    Post subject: Reply with quote

if you are the host, you'll automatically get the client ip when you accept the socket (struct socketinfo)
_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Oct 13, 2007 10:44 am    Post subject: Reply with quote

I have a question. I was watching a vb tutorial on just a simple chat with only one person. But it demands one of the people to have the server open and the other the client. What I'm wondering, is if you and your friend don't say like"Ok, you always run the server, I always run the client." Is there anyway to make it so it can detect if the two servers are open and then change one to the client. I was going to ask how msn did this and then I realized they probably have a server somewhere running that is used as a middle man in the process to send data from each client, also connecting each otehr to the ip and port.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites