Added new lock function based on sockets.