| View previous topic :: View next topic |
| Author |
Message |
ShurikeN Advanced Cheater
Reputation: 0
Joined: 09 Jan 2008 Posts: 84
|
Posted: Sat Mar 21, 2009 7:35 am Post subject: Not Sending Problem |
|
|
I've been trying to make this work but I'm getting no luck. I've included the library needed to compile the program and it runs well but the problem is that it doesn't send the packets to the server. Can you point out where I might have made a mistake?
| Code: |
#include <iostream>
#include <windows.h>
#include <winsock2.h>
using namespace std;
int main()
{
char *message = "<iq type=\"get\" id=\"CSTCR_1237635458_84\" to=\"[email protected]/amazilia\" amaz-protocol=\"chat\"><msg room=\"UzZAPers 46\" type=\"groupchat\"><![CDATA[test]]></msg></iq>";
int port = 5222;
sockaddr_in RecvAddr;
WSADATA wsaData;
if( SOCKET_ERROR == WSAStartup( MAKEWORD(2,2), &wsaData ) )
{
cout << "WSAStartup Error!";
return -1;
}
SOCKET sendSocket = socket(AF_INET, SOCK_STREAM, 0 );
if( SOCKET_ERROR == sendSocket )
{
cout << "sendSocket Error!";
return -1;
}
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(port);
RecvAddr.sin_addr.s_addr = inet_addr("125.5.109.124");
while( true )
{
if( GetAsyncKeyState(VK_SPACE) & 1 )
{
int ret = sendto( sendSocket, message, strlen(message), NULL,(SOCKADDR*)&RecvAddr, sizeof(RecvAddr) );
if( ret == SOCKET_ERROR )
cout << "Sending failed!";
else
cout << "Sent!";
Sleep( 500 );
}
if( GetAsyncKeyState(VK_ESCAPE) & 1 )
break;
}
return 0;
}
|
Whenever I hit SPACE I get the Sending Failed message.
_________________
| Code: | XXXXXX XXXXXX
XXXXX XXXXX
XXXXXXXX
D I R E C T
XXXXXXXX
XXXXX XXXXX
XXXXXX XXXXXX
GameDev
|
|
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sat Mar 21, 2009 12:56 pm Post subject: |
|
|
| Code: | | SOCKET sendSocket = socket(AF_INET, SOCK_STREAM, 0 ); |
| MSDN wrote: | | Connection-oriented sockets such as SOCK_STREAM provide full-duplex connections, and must be in a connected state before any data can be sent or received on it. A connection to another socket is created with a connect call. |
| MSDN wrote: | | The sendto function is normally used on a connectionless socket to send a datagram to a specific peer socket identified by the to parameter. Even if the connectionless socket has been previously connected to a specific address, the to parameter overrides the destination address for that particular datagram only. On a connection-oriented socket, the to and tolen parameters are ignored, making sendto equivalent to send. |
| MSDN wrote: | SOCK_STREAM
A socket type that provides sequenced, reliable, two-way, connection-based byte streams with an OOB data transmission mechanism. This socket type uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).
SOCK_DGRAM
A socket type that supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. This socket type uses the User Datagram Protocol (UDP) for the Internet address family (AF_INET or AF_INET6). |
Make use of WSAGetLastError & FormatMessage for descriptive error messages.
|
|
| Back to top |
|
 |
ShurikeN Advanced Cheater
Reputation: 0
Joined: 09 Jan 2008 Posts: 84
|
Posted: Sat Mar 21, 2009 5:43 pm Post subject: |
|
|
Found a new problem. It's successfully sent but not to the correct IP address. I traced it with WPE Pro and it says the packets are sent but with NO IP ADDRESS of the receiver? Oh god
_________________
| Code: | XXXXXX XXXXXX
XXXXX XXXXX
XXXXXXXX
D I R E C T
XXXXXXXX
XXXXX XXXXX
XXXXXX XXXXXX
GameDev
|
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Mar 21, 2009 7:11 pm Post subject: |
|
|
| Use send, not sendto
|
|
| Back to top |
|
 |
ShurikeN Advanced Cheater
Reputation: 0
Joined: 09 Jan 2008 Posts: 84
|
Posted: Sun Mar 22, 2009 7:11 pm Post subject: |
|
|
I just found out that the server does not respond whenever I send the packets thru a new socket, but thru an already open socket and with right socket ID the server then responds.
Is there anyway i can change my socket ID? So far im using WPE to change my socket ID but i don't want my program to be WPE-dependent.
_________________
| Code: | XXXXXX XXXXXX
XXXXX XXXXX
XXXXXXXX
D I R E C T
XXXXXXXX
XXXXX XXXXX
XXXXXX XXXXXX
GameDev
|
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Sun Mar 22, 2009 7:14 pm Post subject: |
|
|
Hook the function that creates the socket in your game.
| Code: | | socket(), WSASocket() |
_________________
|
|
| Back to top |
|
 |
|