i am kinda new to socket programming. wrote the below code for a server. but getting the bind error everytime. i even tried changing the port number(currently is 13 daytime) but doesnt work. please suggest.
#include"header.h"
int main(int argc,char **argv)
{
int listenfd,connfd,retbind;
struct sockaddr_in servaddr;
char buff[MAX];
time_t ticks;
if((listenfd=socket(AF_INET,SOCK_STREAM,0))<0)
{
printf("socket error");
exit(1);
}
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY); //instead of this use
servaddr.sin_port=htons(13);
if((retbind=bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr)))<0)
{
printf("bind error %dn",retbind);
exit(1);
}
listen(listenfd,1024);
for(;
{
connfd=accept(listenfd,(struct sockaddr *) NULL,NULL);
ticks=time(NULL);
snprintf(buff,sizeof(buff),"%srn",ctime(&ticks));
write(connfd,buff,strlen(buff));
close(connfd);
}
return 0;
}
convert PHP array to Javascript array
I have a page that gets a request sent from AJAX, and I am trying to convert a PHP array to a javascript array. is this possible? I tried with Json_encode but it doesn't seem to work. is there
"GROUP BY" in arrays
Well i'm looking to do something i usually could do easily using COUNT and GROUP BY if it was a sql query... But this time i'm working with an array...so i have an array that looks like thisCode:
Login page problems
I developed a website a few months ago and I am now having an issue with logging into it. The place that it is hosted just did some upgrades to their servers and for some reason, now my login page
Changing color in GD via variable?
Hey guys, I'm new here. x)I'm very much a noob when it comes to PHP, but I'm trying to learn as much as I can. I've been writing a script which will generate a new image after submitting some hex
I am stumped
OK. Here is what I am trying to do. I have the conditions set, and if the conditions are met, I want to randomly find a user id, and username from a table, and then store each of these names in the
How to store checkbox array in a session, and then be able to add to it?
I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart, but I can't figure out how to not overwrite the sessions array each time new checkbox values are
Socket problem
Hello,Earlier I posted about my problem with my socket script. It took up to 100% CPU usage.Now I found the problem. With another found simple PHP socket script, I saw it has the same problem.The code
random generation
hii need help with generating thisnumbers from 1-12i want to generate in random order 60 times in total the numbers 1-12and generate 5 results from each number.so in the total of the 60 return result
PHP and XML image gallery variable issue
I'm trying to display the large image on the same page as the thumbnails, to do that I'm passing a variable called $current. I know that the code to display large image works, because it works when no
Date help - fetch dates for Mondays between xxx and yyy?
Does anyone know the best way to do this? I have two dates, say:2010-01-26 and 2010-05-30and I want to return the dates of all the Mondays between them:2010-02-012010-02-082010-02-15....etc.Thanks