Just ask directly: are you a man or a woman? (casually: are you a guy or a girl?)
"What is your sex?" makes me feel like a farm animal or house pet, examined by a veterinarian.
"What is your gender?" makes me think you're looking at me but can't decide if I'm male or female. (I'll grow a beard, OK?)
If this is for online chat, just "asl?" is fine (age, sex, location?).