Recent Notes

Displaying keyword search results 1 - 9
Created by magnum on September 11, 2012 12:38:00    Last update: September 11, 2012 12:38:00
From bind man page: SYNOPSIS #include <sys/types.h> ... The bind call assigns an address and a port to a socket. That's it. There's no mention of client or server, so it can be used on a client socket or a server socket. But it's necessary for a server socket, otherwise clients do not know how to contact the server. For a client socket, the call is optional. When a client connects to a server or sends a message for the first time, a dynamic port is assigned to the client if there's no port assigned to it. If a port is bind beforehand, there's no dynamic assignment. Test code: int print_sock_info(int sockfd) { struct so... Prints: Local addr: 0.0.0.0, port: 0 Local addr: 0.0.0....
Created by magnum on September 11, 2012 12:10:03    Last update: September 11, 2012 12:10:46
Sample code for UDP client and server in C. The server simply echos back the client message. The client stays in "receive" loop to demonstrate the connection-less nature of the UDP protocol. Server code: #include <stdio.h> #include <stdlib.h> #incl... Client code: #include <stdio.h> #include <stdlib.h> #incl... Try it out: Start the server with: ./udpserver 8888 Send message to server: ./udpclient localhost 8888 "Hi, it's me! " Server console displays: Received from 127.0.0.1:41776: Hi, it's me! UDP is connectionless. Send a message from a second client to the first client: $ ./udpclient localhost 41776 "From client 2" First client console displays: $ ./udpclient localhost 8888 "Hi, it's me! " Re... It should be noted that the distinction between client and server is blurry. The only major...
Created by magnum on February 22, 2012 16:04:38    Last update: February 22, 2012 16:04:38
A simple single threaded echo server: #include <stdio.h> #include <stdlib.h> #incl...
Created by magnum on October 09, 2011 19:53:26    Last update: October 09, 2011 19:53:50
#include <stdio.h> #include <stdlib.h> #incl... UNIXguide.net explains this option well: This socket option tells the kernel that even if this port is busy (in the TIME_WAIT state), go ahead and reuse it anyway. If it is busy, but with another state, you will still get an address already in use error. It is useful if your server has been shut down, and then restarted right away while sockets are still active on its port. You should be aware that if any unexpected data comes in, it may confuse your server, but while this is possible, it is not likely. It has been pointed out that "A socket is a 5 tuple (proto, local addr, local port, remote addr, remote port). SO_REUSEADDR just says that you...
Created by magnum on September 27, 2011 21:51:05    Last update: September 28, 2011 18:02:49
Client socket usually does not call bind . But I've seen code that does and it was puzzling to me what bind does to a client socket. Therefore, this little test program. It retrieves a web url and displays info about the socket. You can optionally give a bind host name/ip and port and see what it does. Here are my test results: $ ./client www.google.com Local addr: 172.16.0.... This is the code: #include <stdio.h> #include <stdlib.h> #incl...
Created by magnum on September 25, 2011 21:51:23    Last update: September 26, 2011 20:49:22
A simple socket client in C. #include <stdio.h> #include <stdlib.h> #incl...
Created by Dr. Xi on November 29, 2010 13:08:05    Last update: November 30, 2010 08:51:34
This sample code sets up a server socket on a specified address and port. I use it to test port binding conflicts. import java.net.*; public class SocketBind ... Note: " netstat -ano " also gives you information on active TCP connections, including listening ports. But there are cases where netstat reports nothing and bind still fails.
Created by Fang on August 10, 2010 21:37:36    Last update: October 25, 2010 20:18:47
The tags <fmt:formatNumber> Format a numeric value as number , currency or percentage - controlled by the type attribute (defaults to number if type is missing). Syntax: <fmt:formatNumber value="numericValue" [type="... Attributes: Name Dynamic? Type Description value true String or Number Numeric value to be formatted. type true String Specifies whether the value is to be formatted as number, currency, or percentage. pattern true String Custom formatting pattern, must follow the pattern syntax specified by the class java.text.DecimalFormat . currencyCode true String ISO 4217 currency code. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. currencySymbol true String Currency symbol. Applied only when formatting currencies (i.e. if type is equal to "currency"); ignored otherwise. It is used only when currencyCode is...
Created by Fang on April 03, 2010 20:21:15    Last update: April 04, 2010 03:30:22
The tags <c:out> The <c:out> tag evaluates an expression and outputs the result on the page. The syntax is: <c:out value="value" [escapeXml="{true|false}"] ... where escapeXml defaults to true and default defaults to empty string "". <c:out value="${expr}" escapeXml="false"/> is equivalent to ${expr} . If a variable is set in multiple scopes, the lower scope wins. In the following example code, attribute1 is set in request, session, and application scopes; attribute2 is set in session and application scopes; attribute3 is set in the application scope. The results are: <c:out value="${attribute1}"/> : Attribute1 request scope <c:out value="${attribute2}"/> : Attribute2 session scope <c:out value="${attribute3}"/> : Attribute3 application scope To access values in higher scopes, you have to specify the scope explicitly, like this: <c:out value="${sessionScope.attribute1}"/> : Attribute1 session...