Raised This Month: $51 Target: $400
 12% 

Unable to read data received from socket?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-02-2016 , 06:09   Unable to read data received from socket?
Reply With Quote #1

I'm currently writing a plugin that communicates with an Android app to forward the chat and game info. I'm pretty new to socket so, I have no idea why this is happening -

PHP Code:
public OnChildSocketReceive(Handle socketchar[] receiveData, const int dataSizeany hFile)
{
    
PrintToServer("Received packet: %i bytes, Message: %s"dataSizereceiveData);
    
bool err false;

    
ByteBuffer status CreateByteBuffer(trueoutsizeof(out));
    
status.WriteInt(0xFFFFFFFF);
    
char key[36];
    
g_ConnectionPassword.GetString(keysizeof(key));

    if(!
StrContains(receiveDatakey) != -1)
    {
        
PrintToServer("Invalid password from client! Kicking it off...");
        
status.WriteByte(PTYPE_CONNECTION_FAILURE);
        
status.WriteShort(sizeof(badPassword));
        
status.WriteString(badPassword);
        
err true;
    }
    if (!
err)
    {
        
ByteBuffer validation CreateByteBuffer(truereceiveDatadataSize);
        if (
ValidateServer(socketvalidation))
        {
            
PrintToServer("Accepting connection...");
            
status.WriteByte(PTYPE_CONNECTION_SUCCESS);
            
status.WriteShort(sizeof(success));
            
status.WriteString(success);
        }
    }

    
out_size status.Dump(out,sizeof(out));
    
SocketSend(socketoutout_size);
    if (
err)
    {
        
int index FindValueInArray(ARRAY_Connectionssocket);
        if(
index != -1)
            
RemoveFromArray(ARRAY_Connectionsindex);
        
CloseHandle(socket);
    }



Whenever I try to print the received data packet from a socket it throws garbled data at me. But if I do receieveData[dataSize-20] or some random number I suddenly get readable output? In this case, an IP address.

__________________

Last edited by 341464; 04-02-2016 at 06:12.
341464 is offline
Send a message via Skype™ to 341464
StSatan
Senior Member
Join Date: Apr 2010
Old 04-02-2016 , 08:18   Re: Unable to read data received from socket?
Reply With Quote #2

Line 110:
PHP Code:
if(!StrContains(receiveDatakey) != -1
0 always != -1

must be
PHP Code:
if(StrContains(receiveDatakey) != -1
StSatan is offline
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-02-2016 , 12:06   Re: Unable to read data received from socket?
Reply With Quote #3

Thanks for pointing that out but it didn't answer my question.
__________________

Last edited by 341464; 04-02-2016 at 12:06.
341464 is offline
Send a message via Skype™ to 341464
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 04-02-2016 , 12:15   Re: Unable to read data received from socket?
Reply With Quote #4

Quote:
Originally Posted by 341464 View Post
Thanks for pointing that out but it didn't answer my question.
Can I see your code to send the infos ? You might want to read my tutorial about sockets.
The problem probably come from the size of the paquets. I had some probelms with the socket extension also, 'cause of the wrong termination of paquets... Normally, it should end with "\0".
EDIT: The size is definitly the problem.
__________________
Want to check my plugins ?

Last edited by Arkarr; 04-02-2016 at 12:22.
Arkarr is offline
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-02-2016 , 12:39   Re: Unable to read data received from socket?
Reply With Quote #5

Quote:
Originally Posted by Arkarr View Post
Can I see your code to send the infos ? You might want to read my tutorial about sockets.
The problem probably come from the size of the paquets. I had some probelms with the socket extension also, 'cause of the wrong termination of paquets... Normally, it should end with "\0".
EDIT: The size is definitly the problem.
It's odd, socket picked up the 30 bytes data, the same from Wireshark as well. I agree that the null delimiter seems to be off, not sure.
__________________
341464 is offline
Send a message via Skype™ to 341464
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-03-2016 , 03:29   Re: Unable to read data received from socket?
Reply With Quote #6

Bump. I still can't figure out how to fix this.
__________________
341464 is offline
Send a message via Skype™ to 341464
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 04-03-2016 , 04:33   Re: Unable to read data received from socket?
Reply With Quote #7

Quote:
Originally Posted by 341464 View Post
Bump. I still can't figure out how to fix this.
try to add the terminator manually in your string. If you don't mind, you could send me the whole code (thorugh PM if it has to remain private) and I can try to fix it.
__________________
Want to check my plugins ?
Arkarr is offline
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-03-2016 , 07:41   Re: Unable to read data received from socket?
Reply With Quote #8

Quote:
Originally Posted by Arkarr View Post
try to add the terminator manually in your string. If you don't mind, you could send me the whole code (thorugh PM if it has to remain private) and I can try to fix it.
I did try to add the terminator in the end and it still wouldn't show up properly.

Here's the code.
http://pastebin.com/C1FG5PnE

EDIT: Also, ignore the useless ValidateServer function. It was yet to be implemented.
__________________

Last edited by 341464; 04-03-2016 at 07:43.
341464 is offline
Send a message via Skype™ to 341464
341464
Senior Member
Join Date: Dec 2010
Location: GetClientEyePosition
Old 04-03-2016 , 11:23   Re: Unable to read data received from socket?
Reply With Quote #9

Figured it out, if you do %X and then print out the data. It'll only show FFFFFFFF because the rest were cut due to the null delimiter in the packet data before the full message ends. Looks like I'll just have to do something like this now -

Code:
	char server_key[64];
	char client_key[64];
	//Obtain server password
	g_ConnectionPassword.GetString(server_key, sizeof(server_key));
	//Obtain client password
	strcopy(client_key, sizeof(client_key), receiveData[9]);
__________________
341464 is offline
Send a message via Skype™ to 341464
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 04-03-2016 , 12:05   Re: Unable to read data received from socket?
Reply With Quote #10

Erf... Too late. Anyway, good job. I was pretty sure it was 'cause of the delimiter.
__________________
Want to check my plugins ?
Arkarr is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode