CodeByte

Write your code smartly

Category Archives: General

Simple TCP Client Server Communication using Android

The following post is about simple TCP Client Server communication sample using Java code for Android. The steps are simple as defined below. TCP communication is done over inter-network or internal network (not necessary internet working). There must be an IP-Address for destination and a unique port (with unique I mean is not one which is used for standard protocols such as File Transfer Protocol (FTP) uses port number 21, TCP uses port 80) list can be found here for more reference. The port range is from 1 to 65535. Selecting a port from this range and an IP address, you can simply transmit data over network directly to the destination port.

TCP Client connection to TCP server to send data


try{
// Creating new socket connection to the IP (first parameter) and its opened port (second parameter)
Socket s = new Socket("192.168.1.1", 5555);

// Initialize output stream to write message to the socket stream
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

String outMsg = "";

outMsg = "This is Client";

// Write message to stream
out.write(outMsg);

// Flush the data from the stream to indicate end of message
out.flush();

// Close the output stream
out.close();

// Close the socket connection
s.close();
}

catch(Exception ex){
//:TODO Handle exceptions
}

A simple TCP server to receive the TCP packet from client.

TCP Server receive the data using the port as IP address is just mentioned from the source and not required anywhere for TCP Server.


try{

ServerSocket ss = null;

// Initialize Server Socket to listen to its opened port
ss = new ServerSocket(5555);

// Accept any client connection
Socket s = ss.accept();

// Initialize Buffered reader to read the message from the client
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

// Get incoming message
String incomingMessage = in.readLine() + System.getProperty("line.separator");

// Use incomingMessage as required
System.out.print(incomingMessage);

// Close input stream
in.close();

// Close Socket
s.close();

// Close server socket
ss.close();

}
catch(Exception ex){
//:TODO Handle exceptions
}

You can utilize the received message accordingly.

To test the working example on Android devices you must add permissions to AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

Cheers !

 

Hard Disk Partition in Windows 7

After you have installed Windows 7 you might want to partition your drives and create different spaces for different purposes. Here are some easy steps which can help you to perform partition of hard disk easily.
Step1 : right Click on your My Computer Icon and select Manage.
Step2: A window will open, on the left side under computer management there are some options, select Disk Management under the Storage header.
Step3 : your Disk details will be displayed with used memory and free memory.
Step4: In the bottom part you will see descriptive information of disks. Right click on the one you want to shrink or divide and select Shrink volume. It will query from the system and will take few minutes.
Step5: now a window with the total size of the drive in MegaBytes will be displayed along with default shrink memory in MBs is also filled in. Remember to fill out the memory you want to partition in MBS i.e 1024 for 1GB and so on.
Step6: After you provide the memory of new partition proceed to next step and keep providing the information about the new partition as per your requirements also you can provide the name of new partition.
Step7: you are now done with the new partition after ending the process and you can see it in your drives that one more partition is added.
Enjoy!

Job Resume Template

Not getting a Job? Try making your resume attractive. Resume makes a great impact on the Employer so find out some good resume templates here.

Download to preview them correctly !

Template 1

Template 2

Template 3

Template 4

Template 5

Template 6

More in Future !

Good Luck !

Microsoft Kinect

Kinect is a product of Microsoft which is used to sense the body movement of the humans. Kinect is majorly used with the Microsoft’s gaming console known as XBOX where you can play games by live action. Xbox is connected to kinect and kinect using its camera detects the points of the skeleton of the human body and performs respective actions on the gaming screen.

Kinect helps users to interact to display devices such as gaming consoles or PC without any touch or physical interactions. That leads to know about NUI (Natural User Interaction) which means to interact with the system without touching in fact using sensors to perform actions. RGB camera is integrated in Kinect to detect the scene. Not only this Kinect also detects the voice and perform actions what are assigned to that voice. Yes, Kinect is now widely used for programming different software which are useful in daily life of different people.

Kinect had a processor inside itself which makes the processing faster than the normal web cam of the computer systems.

Following is the image representing the kinect device description.

3D depth sensor is used distinguish the distance of the objects in the scene detected by the RGB camera and result in a image defining the scene in a gray scale mode (by default). Closer the object darker the color.

Welcome

I welcome you all to my blog. I love sharing my experiences through writing post here so I will try my best to share my knowledge frequently. You can write me through any medium from about page for any correction or just simply write a comment below respective post.

Design a site like this with WordPress.com
Get started