Java Socket Example

Categories: Java; Tagged with: ; @ April 2nd, 2013 0:43

Requirement:  Client send message to Server, Server get the message and return to Client.

Codes:

MesgServer:

package com.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import com.common.LogHelper;

/**
 * ServerSide: receive message from Client and return it. 
 * @author Guoliang
 *
 */
public class MesgServer implements Runnable{
	
	public void run() {
		LogHelper.log("ServerStarted");
		try {
			ServerSocket serverSocket = new ServerSocket(8888);
		
			while (true) {
				
					Socket socket = serverSocket.accept();
					LogHelper.log("Request: " + socket.toString());
					
					BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
					PrintWriter out = new PrintWriter(socket.getOutputStream());
					
					out.println("Connected!");
					out.flush();
					
					String lineInput;
					while ((lineInput = in.readLine()) != null) {
						LogHelper.log("GotMesgFromClient: " + lineInput);
						out.println("ServerReturnMsg: " + lineInput);
						out.flush();
						if("exit".equals(lineInput)) {
							break;
						}
					}
					
					out.close();
					in.close();
					socket.close();
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

MesgClient

package com.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import com.common.LogHelper;

public class MesgClient {

	/**
	 * Send mesg to server side.
	 * @param args
	 * @throws IOException 
	 * @throws UnknownHostException 
	 */
	public static void main(String[] args) throws UnknownHostException, IOException {
		
		// Start server. 
		new Thread(new MesgServer()).start();
		
		Socket socket = new Socket("localhost", 8888);
		LogHelper.log("Connecting...");
		
		PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        
        LogHelper.log(in.readLine());
        
        // Simplest testing
        out.println("Hello!"); 
        LogHelper.log(in.readLine());
        
        // Read user input.
        BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
        String strInput = null;
        while ((strInput = stdIn.readLine()) != null) {
        	out.println(strInput);
        	LogHelper.log("Send: " + strInput);
        	LogHelper.log(in.readLine());
		}
	}
}

Output:

[Thread-0]ServerStarted
[main]Connecting...
[Thread-0]Request: Socket[addr=/127.0.0.1,port=5569,localport=8888]
[main]Connected!
[Thread-0]GotMesgFromClient: Hello!
[main]ServerReturnMsg: Hello!
liguoliang.com  // user input.
[Thread-0]GotMesgFromClient: liguoliang.com
[main]Send: liguoliang.com
[main]ServerReturnMsg: liguoliang.com

JIRA: User have the permission but can not see ‘log work’ context menu

Categories: Development Notes; Tagged with: ; @ April 1st, 2013 19:58

Problem:  User have the permission, but unable to log work.

Cause & Solution:

Follow these steps:

    1. Ensure the user has the “Work on Issues” permission in the permission scheme. It’s possible that the user is not in the group, or not in the project role.
    2. Ensure that time tracking is enabled globally.
    3. Check whether the issue is ‘Closed’, or the workflow has put the issue in a state that is uneditable.
    4. Ensure that the Time Tracking field is visible (not hidden) on the Field Configuration.

      Note that this last procedure will allow editing of closed issues. If you wish to edit only this one issue, simply reopen the issue, add time tracking, and re-close.

      1. Choose the issue that is being affected by this problem (e.g. issues with Closed status).
      2. Navigate to Administration >> Global Settings >> Workflows and check for the Active workflow that the issue is using.
      3. Create a draft workflow since the current workflow is in an Active state.
      4. Click on View Properties for the affected issue status.
      5. Delete jira.issue.editable if it’s set to false.
      6. Add a new property with the same property key (jira.issue.editable) but set to true.
      7. Publish this workflow draft.

For my case, the project has it’s own field schema, and the ‘Time tracking’ filed was hided, after ‘show’ the ‘Time tracking’ filed,  user can log work.

 

For more details: https://confluence.atlassian.com/display/JIRAKB/Unable+to+Log+Work

Bitbucket: Free Git Private Repository 免费私有Git空间

Categories: Development Notes; Tagged with: ; @ March 31st, 2013 11:48

About Bitbucket

Host your code online in as many public and private repositories as you want. Free for 5 users.

Give your code a home on the web. Share what you’re working on with your colleagues, collaborators, or potential employers.

All 5 user accounts are FREE.

image

Checkout: https://bitbucket.org/

骑自行车@新加坡东海岸

Categories: 垃圾山; Tagged with: ; @ March 17th, 2013 0:33

临上地铁时, 我们才意识到大家都没去过, 也不知道路线. 手机搜了一下, 选择了如下路线:

  1. 绿线到Eunos下车;
  2. Eunos去往A点换巴士: 966或15;
  3. 坐到位置B, Parkway parade shopping centre
  4. 然后步行过地道到海边.

 

image

 

进去后发现近处并没有租车的地方, 打听了一下比较近的在后头, 于是转向后走到C, 租上车子(头一小时S$6/辆, 押证件, 不能异地还),  一路走走停停, 最后又骑回来还车子.

连走带骑,差不多12公里.  然后又打车去Changi village 吃饭.

乱拍的几张照片:

IMGP4518

IMGP4522

IMGP4546

 

回来后发现其实是有正儿八经的文档的:

 

image

http://www.nparks.gov.sg/cms/docs/diy_guide/ECPCN_D5.pdf

WordPress: batch deleting spam comments 批量删除垃圾回复

Categories: Development NotesWordPress; Tagged with: ; @ March 16th, 2013 10:50

Use sql to delete all the spam comments quickly:

Status of comment

SELECT DISTINCT comment_approved  FROM `x_comments`

Results:

0 – Pending

1 – approved

spam – spam

trash – trash

 

Deleting SQL

–delete spam & trash:

DELETE FROM `dbName`.`x_comments` WHERE comment_approved = 'spam' or comment_approved = 'trash'
--delete pending:
DELETE FROM `dbName`.`x_comments` WHERE comment_approved = '0'

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.