Packets? Are you sure you shouldn't be using UDP for this problem? It seems to me that the locators want to send infrequent 'fire and forget' messages to your server – exactly what UDP is designed for. The fact that you're immediately closing the TCP connection you create strongly implies that you want a non-persistent-connection protocol.
As for what's actually wrong with your code, if you want to persist with TCP:
- You are blocking on stream.Read on the same thread as you accept connections. That means that if a locator attempts to connect to your server while you are waiting from data from another, it will fail (you are not accepting threads at that point). You should use the asynchronous methods, or at least put data reading into a separate thread from the acceptance. See the server in my sockets library for a way of handling accept and receive appropriately using asynchronous methods (but note that receive is done in a different class). Right now your server can only handle one connection at once ... not at all scalable.
- You are assuming that a single call to Read returns all the data that will be sent from that source. Even if you send it in one call, this is not necessarily the case (even if the size of the data is under the packet transfer limit, I think – and if it is over, it is certainly not guaranteed. I recommend closing the connection from the sender's end, if you want a fire-and-forget – then the server can assume that a closed connection has sent all its data. (That doesn't work if a client requires an acknowledgement but you're not doing that now.)
- You close the whole server if you get a SocketException, which is most likely to occur in Read for a single client. You want two traps, one around Accept and one around Receive/Close, the first can close the server but the second should only close that client.