I'm creating a server/clinet, but I've a problem. If I boot the server and the client for the first time, everthing works fine. Then I close them, I boot them again in few seconds, and I receive e "connection refused" error in the client. I always boot the server first, and the client after. Here's the code. DoLogin is an easy function with 2 read and 2 write. What's wrong in this code?  server.c  int main(){     int ds_sock;     struct sockaddr_in my_addr;     ds_sock=socket(AF_INET,SOCK_STREAM,0);      memset(&amp;my_addr,0,sizeof(my_addr));     my_addr.sin_family=AF_INET;     my_addr.sin_port=htons(25000);     my_addr.sin_addr.s_addr=INADDR_ANY;      if(bind(ds_sock,(struct sockaddr *)&amp;my_addr,sizeof(my_addr))&lt;0){         printf("Error in bind");     }      listen(ds_sock,2);     int ds_sock_acc;     struct sockaddr_in addr;     size_t sin_size = sizeof(struct sockaddr_in);      if((ds_sock_acc=accept(ds_sock,(struct sockaddr *)&amp;addr,&amp;sin_size))&lt;1){         printf("Error accept");     }     printf("Connected\n");     char *usr = DoLogin(ds_sock_acc);     printf("%s is connected\n",usr);      close(ds_sock_acc);     close(ds_sock);      return 0; }   client.c  int main(){     int ds_sock;     ds_sock = socket(AF_INET, SOCK_STREAM,0);      int ret;     struct sockaddr_in Eaddr;     Eaddr.sin_family = AF_INET;     Eaddr.sin_port = htons(25000);     Eaddr.sin_addr.s_addr=inet_addr("127.0.0.1");     ret = connect(ds_sock,(struct sockaddr *)&amp;Eaddr,sizeof(Eaddr));     if(ret==-1){          printf("Error connect");         perror("error:");         exit(EXIT_FAILURE);     }     printf("Connect OK\n");     char *usr = DoLogin(ds_sock);     printf("Logged in as %s\n",usr);      close(ds_sock);     return 0; }
How do I make sure that a socket bound to a port is properly released on process exit such that the port can be reused without bind() failing with EADDRINUSE? I've written a tiny program which just creates a socket, binds it to a fixed port, waits for a connection and then immediately terminates. When I rerun the program, the bind() call fails with EADDRINUSE, but if I wait a few minutes, it succeeds.  Is there a way I can explicitly "unbind" the socket, thereby freeing the port number?
number theory about index Given the congruence $x^3 \equiv a \pmod p$, where $p \geq 5$ is a prime and $\gcd(a,p)=1$, prove the following:   If $p \equiv1 \pmod 6$, then the congruence has either no solutions or three incongruent solutions modulo $p$ If $p \equiv5 \pmod 6$, then the congruence has a unique solution modulo $p$   Help me...  I don't know what I learn because Prof teaches so quickly.  So I need your help to organize my thoughts. A is similar to $A^k$, then each eigenvalue of $A$ is a root of unity Let $A \in \mathbb{C}(n,n)$ and $k \geq 2$ be an integer such that $$A \sim A^k$$. Show that if $A$ is non-singular then each eigenvalue of $A$ is a root of unity.   Attempt: Since $A \sim A^k$, $$PA = A^kP$$ where $P$ is an invertible matrix. Since $A$ is invertible, $0$ cannot be an eigenvalue of $A$. Suppose $$Av = \lambda v \quad v \neq 0$$ then $$PAv = \lambda Pv$$ $$\therefore A^k(Pv) = \lambda (Pv) $$ but this implies that $Pv$ is an eigenvector of $A$. But the eigenvalues of $A^k$ are $\lambda^k$ $$\therefore \lambda^k=\lambda$$ which gives the conclusion required.   My questions is: Is the logic correct? If so, Am I missing any details? If not, then how could I approach this?   Thanks! Import/export 3ds format in Blender 2.8 I need to import and specially export in 3DS format. I know that I can import a file in 2.79 and the copy-paste to 2.8, but then when I copy-paste it back to 2.79 I'm having problems with textures missing. Is there any way to import/export 3ds in 2.8 without using any other version or software like we did in 2.79? The extension is missing in the add-ons repository either. Working in Cycles.  Say I have a "disco ball" with a glossy shader. I'm pointing a spot light to it, and I'm trying to have the reflections of that light illuminate the diffuse material on the walls with the patterns from the ball.    I get this:    but I'd like to get something like:    For the illustration I placed a point light inside the ball an removed faces. But what I'd like to do is move the light around the ball so that the light reflected from it changes like it would do in real life.   Is that possible at this point?  EDIT:  Just for the record here's the image rendered in LuxRender (yet another program to learn...) I came upon an interesting way to relatively quickly compute modular exponentiation with large numbers. However, I do not fully understand it and was hoping for a better explanation.  The method basically states if you have $x^y \bmod N$, it can be computed by repeatedly multiplying by $x$ modulo $N$:  $$x \bmod N \rightarrow x^2 \bmod N \rightarrow x^4 \bmod N \rightarrow x^8 \bmod N \rightarrow \ldots \rightarrow x^{2[\log y]} \bmod N$$  This is supposed to calculate in $\mathcal{O}(\log_2 N)$ time.  An example is given:  $$x^{25} = x^{11001_2} = x^{10000_2} * x^{1000_2} * x^{1_2} = x^{16} * x^8 * x^1$$  I don't really understand how this is faster. Aren't you just doing the same thing? You're just breaking down the exponents into representations of base $2$. Also where does $x^{2[\log y]}$ come from? If you're breaking it down into exponents of two where does a logarithm come from? (Aren't logs representations of numbers in exponents of $10$?)  I'm sorry if this appears to be a really stupid question - I have minimal knowledge in math.  Also, I wasn't sure if this belongs here or on stack exchange, so give me the word and I'll move it. "I had my house [be] burned down" I have found out that using the verb be in passive constructions such as:      I had my house be burned down    is incorrect, therefore it should be      I had my house burned down.    But is it possible instead of be to use get? E.g.      The wire is passed through the pliers in a specific way to avoid having it get bent.   The rope had its surface wear.   The rope had its surface get worn.   The rope had its surface worn.   The first two sound very odd to me, but just for clarification could you please point out the errors and which ones are correct? Or is using get, be it in -ing or the to infinitive, in any situation along with have incorrect? How does long to int cast work in Java? What is the difference between Fact and Truth? I'm curious about the difference between Fact and Truth. I was searching on the internet if I could find it. But still I'm confused about the exact meaning. I first read the forum discussion here  where an author has given two examples for each like below     A fact is a reality that cannot be logically disputed or rejected. If   I say "fire is hot," I don't care how great your reasoning skills are,   if you touch fire your skin will burn (and don't give me that "but   people can walk on hot coals!" bull. There's a difference between the   transfer of heat through conduction and training one's body to deal   with the agonizing pain of said conduction). Now when I say this, I am   not speaking a truth, I am speaking a fact. If you say "fire is not   hot," you are not lying, you are incorrect. Facts are concrete   realities that no amount of reasoning will change. When one   acknowledges a fact, they are doing just that. Facts are not   discovered, facts are not created, facts are simply acknowledged.      A truth on the other hand, is almost the opposite. Truths are those   things that are not simply acknowledged, but must be discovered, or   created. If I say "God exists," and I possess strong reasoning for the   affirmative of that statement, then God really does exist, that is a   reality. However, if another individual possesses strong reasoning for   the negative, and because of this reasoning they believe that God does   not exist, then that is also a reality. If we were to debate our   ideologies, and my reasoning appeared stronger than theirs, they may   choose to adopt my belief that God does exist. If they do, then the   existence of God is just as true as the nonexistence of God which they   believed a week ago. Truths, as opposed to fact, are much more fluid   and malleable than their empirical counterparts.   and followed by further discussion.  Then I found this . Article from above link says like below:     Facts are notes and lyrics on sheet music.  Truth is what the singer   gives to the listener when she’s brave enough to open up and sing from   her heart.   But still curious about the difference between both of them.  In our daily life, in general conversation, we generally use these both terms interchangeably. Then what is the difference? Are they synonym or have specific difference? What Do the Gringotts Goblins Do With Muggle Money? ‘But you’re Muggles!’ said Mr Weasley delightedly. ‘We must have a drink! What’s that you’ve got there? Oh, you’re changing Muggle money. Molly, look!’ He pointed excitedly at the ten-pound notes in Mr Granger’s hand.   Chamber of Secrets - page 47 - UK Hardcover - chapter 4, Flourish and Blotts   So Gringotts exchanges Muggle money for Wizarding money. What do the Goblins do with the Muggle money after the exchange has been made? Is it possible they keep a stash of Muggle money on hand for reverse exchange purposes, or do they surreptitiously feed the money back into the Muggle economy?  What do Goblins do with Muggle money? A cardinal $\kappa$ such that $2^{\lambda}<\kappa$ for all $\lambda<\kappa$ is regular? A cardinal $\kappa$ such that $2^{\lambda}&lt;\kappa$ for all $\lambda&lt;\kappa$ is regular?  I would appreciate very much an answer How to get current CPU and RAM usage in Python? Sorry if this is a stupid question, but I am mainly working with 5V PIC circuits and now want to integrate a component (nRF24l01+) that needs a 3.3V supply.  As I have a box full of ~7V wall-warts, I normally use a 7805 or similar LDO regulator to power the circuit. Now I want to also get 3.3V without using a separate external supply.  I'm looking for guidance on the "right" way to do this. I think the options are:   Use a voltage divider on the output of my 5V regulator to get 3.3V Use a 3.3V LDO regulator fed directly from the 7V wall-wart   Use the output of the 5V regulator as input to a 3.3V regulator   I can see that all of these would work (would they?) and that option 3 seems to waste least power, but I don't know what gotchas might arise by chaining two regulators like this.  What things do I need to consider when making this choice? SQL Server 2008 server cannot connect to itself with alias name or "localhost" We have a SQL Server 2008 ENT 64bit SP3 server running Server 2008 R2 Standard SP1 64-bit.  This is also a windows/sql clustered environment.  There is the cluster alias for the server, and then we have 2 AD DNS aliases as well for the server  Suddenly I can't connect to the sql instance in Management Studio, or with a Powershell Invoke-SQLcmd IF I am doing it from that actual server, when using one of the dns alias names, or "localhost".  If I use the Cluster alias name it works and if I use the other dns alias name it works.  Using management studio with the non-working dns alias I get "Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."  If I use localhost, I get "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)"    Shared Memory and TCPIP are enabled in SQL Server Config manager but named pipes is not.  But we've NEVER had named pipes enabled, and don't have it enabled on any of our other sql servers and they're set up the same (clustering, dns aliases...etc) and are having no issues.  I've Googled around and had a view people suggest listing what other SQL servers it can see (cmd prompt sqlcmd -L)  If it do it from a good server I see all other servers on my network including the "bad" one.  If I do that command from the "bad" server, I get no results at all.  Pretty much checked everything from this blog and it's all ok except the sqlcmd -L issue I just mentioned above.    Windows firewall is not enabled.  This was working just fine for a couple of years.  I'm not sure when this started happening, but I know that at some point, it was not happening.  And the other kicker...it's only happening locally to this server.  If I connect with management studio or run a powershell Invoke-Sqlcmd from another machine, or my local machine connecting to the "bad" server, it works fine no matter what alias I use.  I'm stumped.  I think it sounds like an issue with the AD alias (there are 2 ad aliases, 1 works locally the other doesn't)...but not being able to connect with localhost makes me question that.  any help is greatly appreciated. How do I set up an account with multiple users? Prove that if $d$ divides $n$ then $φ(d)$ divide $φ(n)$ for $φ$ denotes Euler’s $φ$-function.  I know that $d|n$ mean there exists some integer $k$ such that $n=kd$, but how can I use this to prove $φ(d)$ divide $φ(n)$ Minimize the sum of distances between two point and a circle Justify text inside itemize environment with beamer class I want to copy all images on my computer to a single folder I want to copy all images of any file extension like .jpg, .png, .gif, etc. from all folders and subfolders in my PC hard drive (which has two partitions) to a single folder.  The total number of images I have is 250,000. How can I install Whatsapp web app on Ubuntu? I found a similar question , but here I am asking for the WhatsApp desktop webapp so that I can directly access the application without opening a browser. How do I downgrade Minecraft to play on a server running an older version?