I believe that I can help with this.
And by the way, this isn't to imply that I was 'socially enlightened' way before you or anything. It's my circumstances that provided the missing key.
By sixth grade, I had gone to nine different schools (divorced parents, mother changing colleges, father transferred due to promotions etc...).
I could never understand why it was so difficult to develop friendships. By forth grade, I surmised that this was due to always being the "new kid." But then something happened. A newer kid came aboard and over night, started developing all these new friendships.
Although the above sounds kind of depressing (and it sure felt that way) it was the best thing to happen and it's identical to your story.
I started applying self-objectivity. I started looking at myself and other students that weren't very popular. I began to ask myself; what is is about these less popular kids that I also didn't like? I then started becoming cognizant of my own behavior(s). I then started asking myself; if I were them, would I want to be around someone like this?
It took a while to adjust and transform, but by sixth grade, I became one of the 'average' guys... and by 8th grade, I actually became (so-called) "cool." I won't lie. At times it almost seemed like I made a deal with the devil or something. Five years earlier, I would have never guessed that I could be at the top of the game... but there I was.
The short version:
Getting rejected by friends is the same gift as getting rejected by women. Although it may not seem like constructive criticism, in a dark twisted way, it is. With each new social encounter, we have the opportunity to apply our new self-awareness. And with each positive reaction (or negative) we have a new opportunity to calibrate and improve.
There's absolutely nothing special about me at all. A lot of my peers think that there is... because I don't do half bad with women and have a fairly good social circle. I was never a 'natural' but if you do the hard work (introspection and apply self-objectivity) you can achieve the same result.