Recent Notes
Displaying keyword search results 1 - 10
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 voodoo on August 03, 2012 08:42:38
Last update: August 03, 2012 09:31:25
The C function getsockopt lets you get the error codes with the option SO_ERROR . The possible error numbers are defined in the global errno.h . The relevant values are:
#define ETIMEDOUT 110 /* Connection timed out */
...
But here's the whole list on my Linux system ( /usr/include/asm-generic/errno.h ):
#ifndef _ASM_GENERIC_ERRNO_H
#define _ASM_GENER...
Created by Fang on February 23, 2012 14:25:57
Last update: March 01, 2012 13:53:59
Some example snippets for Spring message configuration and usage.
To configure a message source in Spring context (basename=messages):
<bean id="messageSource"
class="org.springf...
Locale change interceptor can also be setup with:
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
The messages file should be named messages.properties (or messages_en.properties , etc.) and located on CLASSPATH , for example: WEB-INF/classes .
To use a message resource in JSP:
<%@ taglib prefix="spring" uri="http://www.springf...
Created by James on February 02, 2012 16:00:15
Last update: February 02, 2012 16:00:15
Video for Everybody seems to be a generic way to embed video in a web page, even without flash. This code snippet comes from that site.
<!-- first try HTML5 playback: if serving as XML, ...
Created by Dr. Xi on February 01, 2012 12:55:28
Last update: February 01, 2012 12:55:28
You can define environment variables in the Tomcat context.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<Context...
which is equivalent to the following in web.xml :
<env-entry>
<env-entry-name>varName</env-entr...
In Java code, the variable can be looked up like this:
// import javax.naming.Context;
// import javax...
Created by Fang on November 10, 2011 09:26:12
Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines!
<?xml version="1.0" encoding="UTF-8"?>
<xsd:sch...
Created by Fang on September 07, 2009 20:44:15
Last update: November 03, 2011 14:43:19
Step 1: Repackage a web app as EAR A Java EE application is a multimodule Maven project. At the very least you'll need to package a WAR and an EAR. To get started, I'll simply re-package the simple webapp as an EAR. Create a directory named javaee-app Copy the webapp from here to javaee-app . Rename struts1app to webapp . Create pom.xml under javaee-app :
<project> <modelVersion>4.0.0</modelVersion>... Create a directory named ear under javaee-app . Create pom.xml under ear : <project> <modelVersion>4.0.0</modelVersion>... Modify pom.xml in the webapp directory so that it looks like this: <project> <modelVersion>4.0.0</modelVersion> ... Build with " mvn package " in the javaee-app directory. You can see that ear-1.0.ear is successfully generated in javaee-app/ear/target . Maven successfully resolves dependencies between the sub-projects....
Created by freyo on May 13, 2011 15:45:29
Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator.
build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<man...
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<Lin...
res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<res...
src/com/android/xmltool/DumpXml.java
package com.android.xmltool;
import java.ut...
Screenshot
Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by freyo on September 09, 2011 11:43:36
Last update: September 09, 2011 11:45:45
When you run automated Android tests with Eclipse or from the command line, you get text output, which isn't good for reporting purposes. If you run a large set of test cases with automated build, the text report isn't very helpful. Fortunately, Android CTS generates test reports in XML with accompanying XSL to make it look nice in a browser. To run your own tests with Android CTS: Download Android CTS Make a new directory MyRepository under android-cts , alongside the existing repository directory. Copy host_config.xml from repository to MyRepository Create directory plans under MyRepository , add a test plan ( MyTests.xml ):
<?xml version="1.0" encoding="UTF-8"?> <TestPla... Create directory testcases under MyRepository . Copy TestDeviceSetup.apk from repository/testcases to MyRepository/testcases Under MyRepository/testcases , create a test...
Created by freyo on September 07, 2011 16:46:14
Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...