Recent Notes
Displaying notes 71 - 80
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 September 11, 2012 11:59:43
Last update: September 11, 2012 11:59:43
Exerpt from bash documentation. HISTORY EXPANSION The bash shell supports a history expansion feature that is similar to the history expansion in csh. This feature is enabled by default for interactive shells, and can be disabled using the +H option to the set builtin command. Non-interactive shells do not perform history expansion by default. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly. History expansion is performed immediately after a complete line is read, before the shell breaks it into words. It takes place in two parts. The first is to determine which line from the history...
Created by magnum on September 11, 2012 11:55:43
Last update: September 11, 2012 11:55:43
Excerpt from bash documentation. Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion. There are three quoting mechanisms: the escape character , single quotes , and double quotes . A non-quoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline> . If a \<newline> pair appears, and the backslash is not itself quoted, the \<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored). Enclosing characters in single quotes preserves the...
Created by James on August 27, 2012 10:01:07
Last update: August 27, 2012 10:01:07
Some ways to get the tag name of a jQuery object:
Use the prop() function:
$('<a/>').prop('tagName');
$('<a/>').prop('node...
Get tagName from the DOM element:
$('<a/>').get(0).tagName
nodeName from the DOM element seems to do the same:
$('<a/>').get(0).nodeName;
Use the is() function:
$('<a/>').is('A');
$('<a/>').is('a');
Created by Dr. Xi on August 24, 2012 14:20:19
Last update: August 26, 2012 11:48:22
Converting hex number to decimal is surprisingly easy in Python:
$ python
Python 2.7.3 (default, Aug 1 2012, 05...
Created by magnum on August 22, 2012 12:34:49
Last update: August 22, 2012 12:34:49
Add this to head :
<link rel="shortcut icon" href="favicon.ico"/>...
Created by voodoo on August 17, 2012 14:16:06
Last update: August 17, 2012 14:16:06
This C function compares a string against a list of words and returns TRUE if every word is found in the string in the order listed in the word list, FALSE otherwise.
#include <string.h>
#include <stdio.h>
i...
Created by voodoo on August 16, 2012 14:55:21
Last update: August 16, 2012 14:55:21
Option 1: use the function tolower :
/* lower case Z */
char c = tolower('Z');
Option 2: logical or with ' ' :
/* lower case Z */
char c = 'Z' | ' ';
/...
Created by Dr. Xi on August 15, 2012 12:05:39
Last update: August 15, 2012 12:05:39
Use OpenSSL's s_client command to fetch a page manually:
$ openssl s_client -connect localhost:443 -state -...
Sample session for Google:
$ openssl s_client -connect www.google.com:443 -st...
Resource: SSL/TLS Strong Encryption: FAQ