The Little Guy Posted November 14, 2008 Share Posted November 14, 2008 I am working with sockets, and I don't know how to fix the following error: PHP Warning: socket_bind(): unable to bind address : Only one usage of eachsocket address (protocol/network address/port) is normally permitted. in C:xampphtdocsindex.php on line 10 I know it is because I make a file and run it on a port, but how do I remove it from that port, so when I run the file again, it will work instead of give me that error? Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/ Share on other sites More sharing options...
.josh Posted November 14, 2008 Share Posted November 14, 2008 Are you using socket_close? Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690499 Share on other sites More sharing options...
The Little Guy Posted November 14, 2008 Author Share Posted November 14, 2008 yes <?php // set some variables $host = "localhost"; $port = 6667; // don't timeout! set_time_limit(0); // create socket $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); // bind socket to port $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n"); // start listening for connections $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); // accept incoming connections // spawn another socket to handle communication $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input $input = socket_read($spawn, 1024) or die("Could not read input\n"); // clean up input string $input = trim($input); // reverse client input and send back $output = strrev($input) . "\n"; socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n"); // close sockets socket_close($spawn); socket_close($socket); ?> Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690508 Share on other sites More sharing options...
.josh Posted November 14, 2008 Share Posted November 14, 2008 Did you read the notes for socket_close? Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690510 Share on other sites More sharing options...
The Little Guy Posted November 15, 2008 Author Share Posted November 15, 2008 It seems like they say to do this: socket_shutdown($spawn, 2); socket_shutdown($socket, 2); socket_close($spawn); socket_close($socket); If I am wrong let me know, otherwise I will try it in a little bit. Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690543 Share on other sites More sharing options...
The Little Guy Posted November 15, 2008 Author Share Posted November 15, 2008 is there any place on my computer I can manually shut these down (windows vista)? Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690556 Share on other sites More sharing options...
.josh Posted November 15, 2008 Share Posted November 15, 2008 possibly through task manager but not 100% Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690560 Share on other sites More sharing options...
The Little Guy Posted November 15, 2008 Author Share Posted November 15, 2008 I got it, and I don't know what I did... Any who, I made my first chat room! Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690567 Share on other sites More sharing options...
.josh Posted November 15, 2008 Share Posted November 15, 2008 well I was thinking maybe if you shutdown the service and/or process related to it, it would close the socket. Other than that, I don't think (again, not 100%) windows really has a built-in socket "manager." I know there are lots of programs you can dl that help out in that dept, or you can program your own through java, c++, vc, etc... Quote Link to comment https://forums.phpfreaks.com/topic/132772-socket/#findComment-690571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.