I'm making a messenger app and I need to know how to set up connections so that somebody could send messages to other via WI-FI.I googled a little and I find something at this page Click Herebut I don't understand it.Here is my main class/StartingPoint (all my code is just a skecht):

import java.io.EOFException; 
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class StartingPoint extends Activity {

Button bSend;
TextView tvClient, etChat;
String mess = "";
String name = "Name";
String usern = "UserName";
String empty;

private ObjectOutputStream output;
private ObjectInputStream input;
private Socket connection;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.startingpoint);

    bSend = (Button) findViewById(R.id.bSend);
    tvClient = (TextView) findViewById(R.id.tvClient);
    etChat = (TextView) findViewById(R.id.etChat);
    final EditText etMess = (EditText) findViewById(R.id.etMess);
    etChat.setEnabled(false); // set etChat not editable
    tvClient.setText(name + " " + usern);

    // setting up sending strings
    bSend.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mess = etMess.getText().toString();
            etChat.append("\n" + name + " : " + mess);
            etChat.setTextColor(Color.BLACK);
            etMess.setText(empty);
        }
    });
    // setting up a chat window
    etMess.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            etChat.setText("");
        }
    });
}
}

My startingpoint.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".StartingPoint"
android:background="#FAFAD2"
>

 <View
    android:layout_width="fill_parent"
    android:layout_height="0.5dp"
    android:id="@+id/separator"
    android:visibility="visible"
    android:background="#90EE90"/>

<Button
    android:id="@+id/bSend"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/etMess"
    android:text="Send" />

<EditText
    android:id="@+id/etChat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/tvIMess"
    android:layout_alignLeft="@+id/tvClient"
    android:layout_alignRight="@+id/bSend"
    android:layout_below="@+id/tvClient"
    android:ems="10">

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/etMess"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText1"
    android:layout_alignParentBottom="true"
    android:ems="10" />

<TextView
    android:id="@+id/tvIMess"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/etMess"
    android:layout_alignLeft="@+id/etMess"
    android:text="Message:" />

<TextView
    android:id="@+id/tvClient"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Name UserName"
    android:textColor="#8A2BE2"
    android:textSize="27dp" />

</RelativeLayout>

This is all of my code and I need to know where and what to put in. I worked in java with servers but when I want to add code from there to here and change it it doesn't work. I know a little about sockets and servers. i hope this will help others too.

You haven't started a connection in your starting code..
-start a connection to the server(either HTTP or socket)
-open the connection
-send the message

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.