exactly , for some reason ( kind of noob to this still so idk why , actually this one was my firs or second script using sockets :) ) , the $chan doesnt work within the sockclose event , so you need to use the actual name of the channel ( #blabla , if you have only 1 ) or a variable like lucius said :)