ā Output not correct
Im doing a Client/server program
the program will give out in output if the user is a minor or not
the issue is that it always says that the user is an adult
idk what im doing wrong
49 Replies
numeroricevuto is the number recieved
from the client
I'll check out
BitConverter
but that sounds wrong
nevermind, seems fineoh
Can you output your byte array to console to make sure it looks how you expect?
There might be some header values or something you weren't expecting
idek how to do it im very bad at coding
Oh wait, I think I know what it is
Your byte array is 256 bytes, and if you're reading just a single int, that's just the first 4 bytes. So then you have a bunch of 0s at the end. So I'm assuming that would convert it to a giant number
Can you set a break point and step through to see what the value of
numeroricevuto
is?i can try
Meh, that's not it either, looks like
BitConverter.ToInt32
just takes the first 4 bytes from whatever startIndex you give it, and you used 0, so that is probably correct, too.
Anyways, to troubleshoot, just check your buffer after the read then check the int after the conversioni wrote console write line and the number
the numer that came out was 13k lol
instead of 16
What values are in the byte array?
Console.WriteLine(string.Join(", ", datiricevuti));
do i need to copy and paste that
yes
put it after the read
alr
ok
Might be cleaner adding a .Take(4)
Console.WriteLine(string.Join(", ", datiricevuti.Take(4)));
So you don't see a ton of 0sdid this and all of this came out
oh
the number i used was 15
So your first 4 bytes are 49 53 0 0
ok
So that would be a big number
yeah when i used console.writeline the number that came out was 13.000 and not 16
How is this data being sent?
Oh wait...
I know what it is haha
oh
what
making sure I'm right. 1 sec
alr
Yeah, it's sending it as text. 49 is the ascii code for 1 and 53 is the ascii code for 5
so that says 15
But you're converting it as if it's a numeric value
oh
so what comand do i need to use now
You could do something like
numeroricevuto = (int)Encoding.UTF8.GetString(datiricevuti, 0, 4);
Not sure if that would work. And even if it does, it would break if it's not an int. So better checking and parsing to int would be betterill try that
it says i cant convert string to int
hm
1 sec, I'm playing around with it now
ok
yeah, tryparse would be better anyways
where should i put this tryparse
Something like that should work
should i write Byte instead of bytes where theres the error
oops sorry, that was from my text code. I'll edit
š
There ya go
yooo it works
thank you man
š
the issue actually lies in your client and not your server
you should just send the bytes for the int, but it sounds like you are sending a string over
it doesn't really make sense to send over bytes of a string just to convert it back into a string and then an int
I don't see where you have shared the client code
the program works now but i didnt send the client because the issue mainly was in the server
i can show you the client if u want
this was my windows form client
the issue definitely looks like it lies in the client
Yeah, wouldn't have been an issue if it was sent as an int
you want to actually parse the textbox as an int and convert it for transport as a byte array
so what you did to fix it but on the client side instead
oh i see
next time ill do that
thank you for helping anyway
do it how you like but I thought I would just weigh in on what the actual issue was š
š