IRC Connection reset by peer

In general, CAP REQ should come first and they can be combined. USER is not required. You should wait for at least the 001 command before sending JOIN commands

< CAP REQ :twitch.tv/membership twitch.tv/commands
> :tmi.twitch.tv CAP * ACK :twitch.tv/membership twitch.tv/commands
< PASS oauth:token_here
< NICK username_here
> :tmi.twitch.tv 001 username_here :Welcome, GLHF!
  :tmi.twitch.tv 002 username_here :Your host is tmi.twitch.tv
  :tmi.twitch.tv 003 username_here :This server is rather new
  :tmi.twitch.tv 004 username_here :-
  :tmi.twitch.tv 375 username_here :-
  :tmi.twitch.tv 372 username_here :You are in a maze of twisty passages, all alike.
  :tmi.twitch.tv 376 username_here :>
> :tmi.twitch.tv GLOBALUSERSTATE
< JOIN #channel_name