Jump to content

Socket


The Little Guy

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/132772-socket/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/132772-socket/#findComment-690508
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/132772-socket/#findComment-690571
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.