I've written a simple HTTP echo server in Racket. When I run the server from within DrRacket and then click the Stop button, my program terminates, but the port that was being used takes an annoyingly long time to close. If I run lsof -i :<port> in my terminal after terminating the program, I don't see anything bound to that port, but DrRacket disagrees and refuses to let me restart my program, telling me that something is already bound to that port.
Is this a bug in Racket, or is there something that I'm missing?
If you are using tcp-listen directly (meaning that you handle all the low-level socket stuff yourself, and manually handle HTTP too), you need to call it with the reuse? parameter set to #t.
If you are using the web-server module, it already sets reuse? to #t so it should already work.
Related
I'm trying to use Octave to open a simple socket server. While debugging, my script crashed after it had bound to a port. Of course, subsequent binds to the same port now fail. How can I close the socket so that I can reuse the port? Right now all I can do is close active entirely, which kills the process that is running the listener.
Ric
To prevent this from happening in the future, you can use onCleanup or unwind_protect to ensure that the socket-closing code always happens, even if your script errors out unexpectedly.
Does anyone know why Eclipse is asking for incoming network connections? I searched around and saw mentions of Code Completion with PyDev, but I disabled code completion in PyDev, restarted, and was still prompted for incoming network connections.
PyDev spawns a shell and connects to it to request information on builtin modules (besides using it to debug a process).
I.e.: The shell is spawn at https://github.com/fabioz/Pydev/blob/master/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/shell/PythonShell.java
and used in:
https://github.com/fabioz/Pydev/blob/master/plugins/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/revisited/modules/CompiledModule.java
So, this may be triggered at multiple places in PyDev (whenever a code completion, code analysis or indexing is done it may be requested and a request for any builtin module is done -- i.e.: anything in forced builtins as explained in http://www.pydev.org/manual_101_interpreter.html).
So, in order to function properly, PyDev really needs that connection to work (otherwise completions and code analysis may not work properly), which means you really have to clear it in your firewall (at least for local connections -- remote connections are only needed if you're going to use the remote debugger).
I'm not sure if this is the only reason but at least one of them could be that PyDev's debugger listens for connections from clients being debugged (this is on 3.9.1 and 3.9.2).
That is, when you debug an application, the TCP flow is from the application to PyDev/Eclipse. Hence it could be that Eclipse needs it just in case you'll want to debug things in the future.
What port is it, 5678? That's the debugger's port.
This is just a wild guess, perhaps this is it in your situation?
I'm developing Firefox addon that communicate with external program by sockets. This program create local socket server on specified port when this addon need it. I would like to ckeck from this addon whether this application has opened this port already.
On Win7 when server isn't created yet I receive in socket created by addon NS_ERROR_CONNECTION_REFUSED in nsIRequestObserver::onStopRequest but if I can feel certain port isn't open when I receive this error?
You try to connect and see if the connection succeeds.
If it doesn't, then the port is not reachable (open).
That's the most obvious and easiest answer.
Other low-level solutions would require polling the OS itself somehow. That would be cross platform specific (so you'd need to write an implementation per platform) and also there is no API readily available so you'd have to mess around with C/C++ or at least js-ctypes, or hack together some ugly "execute this program and check output" stuff. All of which doesn't worth the fuzz.
If you want to find out which "inbound ports" are in use in windows you can use cmd,
if you don't know how to open cmd - open the run dialog by pressing windows-key+r. type cmd and hit enter
type netstat -a and hit enter and it will list all "listening" ports.
more info - http://www.techrepublic.com/blog/it-security/list-open-ports-and-listening-services/
IOLib allows to create a passive socket to listen the clients' connection, before listen is called, we need to call (bind-address) to bind the socket to an specified address/port.
Well, the problem is that the first time I bind the socket to a port, it runs well, then I use C-c C-c in slime to terminate the thread, and run the program again, this time it throws out exception of EADDRINUSE:
<SOCKET-ADDRESS-IN-USE-ERROR 98 :EADDRINUSE "address already in use", FD: 10>
I already set the reuse_addr option to bind-address like that:
(bind-address socket
+ipv4-unspecified+
:port 1080
:reuse-addr t)
But I don't think this is the problem, because when I did the same thing in C, I use Ctrl+C to terminate the process, I can rebind the port, but in slime, the only solution is to restart emacs, it's really not conveninent, so How can I solve this problem, thanks.
When you exit a process, any open file descriptors (including network sockets) are closed, which is why it seems to work in C but not in CL. When a thread terminates, however, this doesn't happen. You'll find that you'll get the desired behavior by using the restart-inferior-lisp command in SLIME.
Not all is lost, however. If you wrap the function in the thread in an UNWIND-PROTECT form, you can arrange for the socket to be closed when the function is exited.
If you telnet to the ip address 192.43.244.18 port 13, you'll get the current time.
well, if I'm not wrong, this is simply a server socket. But there's one thing strange: how's this socket always listening?
If I take a PHP page and program sockets in there, I still have to request for the page first in order to activate the server socket, but this one isn't associated with any pages, and even if a make a perl script, I still have to request for that in order to run the server socket!
My question is: how can I make such a thing - an always listening socket - on a webhost (any language will do)?
You can run the process that's listening on the socket as a daemon (Linux) or service (Windows), or just a regular program really (although that's less elegant).
A simple place to begin would be http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html which teaches you how to make a simple serversocket in Java that listens for a connection on a specific port. The program created will have to be run at all times to be able to accept the connections.