Page 1 of 1

defaultNetworkInterface does not work with 127.0.0.1

Posted: Wed May 02, 2012 11:01 pm
by Kyle W
I have tried to "set the defaultNetworkInterface to 127.0.0.1", then accept connections on port 1234. The problem I am having is that when it opens the network socket, it is bound to "0.0.0.0" still.
Is there any way to make a socket listen to 127.0.0.1 only? The service I am writing should only be accessible from localhost (127.0.0.1).

Thanks!

Re: defaultNetworkInterface does not work with 127.0.0.1

Posted: Fri May 04, 2012 1:56 pm
by BvG
I don't think it's possible to disable connections before they happen (defaultNetworkInterface does something else then you assume, and is only for when you have several possible connections, like wifi and ethernet cable at the same time). However, you can ignore people connecting from the wrong port, which is how standalone firewalls work. For example:

Code: Select all

on mouseUp
   accept connections on port 1234 with message "gotConnected"
   put the result --if port is already open or disallowed by the os, this fails with "Error binding socket"
end mouseUp

on gotConnected theIP
   set the itemdelimiter to ":"
   if item 1 of theIP <> "127.0.0.1" then
      close socket theIP
   else
      --do stuff here
   end if
end gotConnected