check the /etc/services file for a proper port setting for the R/3 message server "sapms<sid>" at 36xx. You can try connecting the SAPgw directly to the dispatcher at port 32xx where XX is the instance number. If that connection is good, then it appears to be a logon load balancing configuration problem which uses the message server.
This is usually because it cannot connect to the message server. Please check the dev_ms for any errors. if it is intermittent it is likely to be a network problem ( see note 500235 Network Diagnosis with NIPING.
Check following SApnotes :
#n21559: Examination of SAPGUI problems could be useful.
Please also check the note 882741 for the more info about this problem.