NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

open class MainActivity widens Activity

{

open Socket sender;

open BufferedReader brrr;

open PrintStream bwwwwaww;

EditText ea;

Catch ba;

TextView ta;

int portNumber;

String ipAwwwdd;

class SocketListener executes Runnable

{

String straaa;

open void run()

{

attemptaaa

{

senderaaa = new Socketadad (ipAddress, portNumber);

braaaa = new BufferedReader (new InputStreamReader(sender.getInputStream()));

bwaaa = new PrintStream (sender.getOutputStream());

bwaaa.println("Connected");

while (real)

{

String sadad = br.readLine ();

CharSequence csadads = t.getText ();

str = csadad + "rn" + adasds;

t.post(new Runnable()

{

open void run()

{

t.setText(str);

}

}

);

}

}

get (IOException e)

{

Log.e(getClass().getName(), e.getMessage());

}

}

}

@Override

verified void onCreate(Bundle savedIadadnstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tadad = (TextView)findViewById(R.id.textView);

tadad.setMovementMethod(new ScrollingMovementMethod());

e adad= (EditText) findViewById(R.id.editText);

portNumber = 4455;

ipAddress = "194.81.104.116";/Change this to the IP address of your PC OR "10.0.2.2"(Gateway to 127.0.0.1 of host)

badad = (Button)findViewById(R.id.button);

badad.setOnClickListener(new View.OnClickListener()

{

open void onClick(View v)

{

new Thread()

{

open void run()

{

String asdadss = e.getText().toString();

bw.println (s);

}

}.start();

}

});

String tadadad = new Thread (new SocketListener ());

tadad.start();

}

}

Make sure to add the going with to the AndroidManifest.xml record

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

Java multi hung server

Used by the Android and Java work zone clients.

import java.io.*;

import java.net.*;

import java.util.*;

class Connection

{

aa

open Socket aaas;

open PrintWriter aaa;

open BufferedReader aaaI;

open boolean aliveadad = false;

open int aadid;

open static int count = 0;

}

open class TCPChatServerThreadv2

{

serverSocket = invalid;

static open List<TCPChatServerThreadTask2> task = new ArrayList<TCPChatServerThreadTask2>();

class TCPChatServerThreadTask2 expands Thread

{

Affiliation adadc;

open TCPChatServerThreadTask2 (serverSocket) hurls IOException

{

cadad = new Connection ();

cadad.s = serverSocket.accept ();

cadad.o = new PrintWriter (c.s.getOutputStream (), certifiable);

cadad.i = new BufferedReader (new InputStreamReader (c.s.getInputStream ()));

cadad.alive = certifiable;

cadad.id = ++ c.count;

System.out.println (c.s.getInetAddress () + ":" + c.s.getPort () + " Connected");

this.startadad ();

}

open void run ()

{

String fromClient;

attemptadad

{

do

{

fromClient = c.i.readLine ();

if (fromClient == invalid) break;/c.alive = false;

System.out.println (c.s.getInetAddress () + ":" + c.s.getPort () + "> " + fromClient);

System.out.println ("Connections: " + task.size() + " ActiveThreads: " + activeCount ());

for (int I = 0; I < task.size(); I ++)

{

task.get(i).c.o.println (casd.s.getInetAddress () + ":" + cadad.s.getPort () + "> " + fromClient);

System.out.println ("To=" + task.get(i).c.s.getInetAddress() + ":" + task.get(i).c.s.getPort() + " id=" +cadad.id + " activecount=" + activeCount () + " message="" + cadad.s.getInetAddress () + ":" + cadad.s.getPort () + "> " + fromClient + """);

}

}

while (fromClient != "quit");

System.out.println (c.s.getInetAddress () + ":" + c.s.getPort () + " Disconnected");

cadad.o.close ();

cadad.i.close ();

cadad.s.close ();

cadad.alive = false;

task.remove(c.id - 1);

}

get (IOException e)

{

System.out.println ("IOEXCEPTION!!!!!");

}

}

}

open TCPChatServerThreadv2 () hurls IOException

{

server__Socket = new ServerSocket (4455);

System.out.println ("Server: Listening on port 4455");

while (certifiable)

{

task.addaaa (new TCPChatServerThreadTask2 (serverSocket));

}

}

open static void essential (String[] args) hurls IOException

{

TCPChatServerThreadv2 aaae = new TCPChatServerThreadv2 ();

}

}

Java TCP Client

This application talks with the Android TCP application through the server.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import java.io.*;

import java.net.*;

import javax.swing.text.DefaultCaret;

class SwingChatGuiV2 grows JFrame

{

open JButton sendButton;

open JTextArea rxArea;

open JTextField txArea;

open JScrollPane sheet;

open Container compartment;

open SwingChatGuiV2 (String title)

{

super (title);

compartment = getContentPane ();

container.setLayout (new FlowLayout());

include = new JTextField (40);

addr = new JTextArea (6, 40);

addr.setEditable (false);

shitter= new JScrollPane (rxArea);

DefaultCaret caret = (DefaultCaret)rxArea.getCaret();

caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM);

sendButton = new JButton ("Send");

container.add (sheet);

container.add (txArea);

container.add (sendButton);

}

}

open class SwingChatClientV2 expands SwingChatGuiV2

{

PrintWriter out = invalid;

open ButtonHandler bHandler;

open SwingChatClientV2 (String title)

{

super (title);

bHandler = new ButtonHandler();

sendButton.addActionListener (bHandler);

txArea.addActionListener (bHandler);

}

private class ButtonHandler executes ActionListener

{

open void actionPerformed (ActionEvent event)

{

String outputLine = txArea.getText ();

out.println (outputLine);

txArea.setText ("");

}

}

open void run () hurls IOException

{

Connection = new Socket ("127.0.0.1", 4455);

BufferedReader in = new BufferedReader (new InputStreamReader (socket.getInputStream ()));

out = new PrintWriter (socket.getOutputStream (), certifiable);

String inputLine;

while ((inputLine = in.readLine ()) != invalid)

{

rxArea.setText (rxArea.getText () + inputLine + "n");

}

out.close();

in.close();

socket.close();

}

open static void main(String[] args) hurls IOException

{

SwingChatClientV2 f = new SwingChatClientV2 ("Chat Client Program");

fadd.pack ();

f.setSize (500, 200);

f.setVisible (certifiable);

f.run ();

}

}
open class MainActivity broadens AppCompatActivity

{

DatagramSocket attachment;

TextView ttt;

EditText eee;

Catch bbb;

class SocketListener executes Runnable

{

String strrrs;

open void run()

{

DatagramPacket parcel;

byte[] buf = new byte[256];

attempt

{

while (genuine)

{

parcel = new DatagramPacket(buf, buf.length);

socket.receive(packet);

String ss = new String(packet.getData());

CharSequence css = ttt.getText();

strrr = cs + "J> " + s + "n";

ttt.post(new Runnable()

{

open void run()

{

t.setText(str);

}

}

);

}

}

get (IOException eee)

{

Log.eee(getClass().getName(), e.getMessage());

}

}

}



ensured void onCreate(Bundle savedInstanceState)

{

superaa.onCreate(savedInstanceState);

setContentView(Raa.layout.activity_main);

attempt

{

attachment = new DatagramSocket();

}

get (SocketException e1) {}

eaa = (EditText) findViewById(R.id.editText);

ttt = (TextView) findViewById(R.id.textView);

ttt.setMovementMethod(new ScrollingMovementMethod());

Catch bbb = (Button) findViewById(R.id.button);

bbb.setOnClickListener(new View.OnClickListener()

{

open void onClick(View v)

{

new Thread()

{

open void run()

{

attempt

{

String sss = e.getText().toString();

t.setText(t.getText() + "A> " + s + "rn");

byte[] buf = new byte[256];

buf = sss.getBytes();

InetAddress address = InetAddress.getByName("10.0.2.2");/Change this to the IP address of your PC OR "10.0.2.2"(Gateway to 127.0.0.1 of host)

DatagramPacket bundle = new DatagramPacket(buf, buf.length, address, 5678);

socket.send(packet);

}

get (IOException e1)

{

e11.printStackTrace();

}

}

}.start();

}

});

String ttt = new Thread (new SocketListener ());

ttt.start();

}

}

Make sure to include

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

To the AndroidManifest.xml document.

Java P2P program.

import java.awt.*;

import java.net.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import java.io.*;

class SwingChatGUI expands JFrame

{

open JButton sendButton;

open JTextArea rxArea;

open JTextField txArea;

open JScrollPane sheet;

open Container compartment;

open SwingChatGUI (String title)

{

super (title);

compartment = getContentPane ();

container.setLayout (new FlowLayout());

ttxArea = new JTextField (40);

rrrxArea = new JTextArea (6, 40);

rrrxArea.setEditable (false);

sheetee = new JScrollPane (rxArea);

sendButton = new JButton ("Send");

sendButton.setEnabled(false);

container.add (sheet);

container.add tt(txArea);

container.addaa (sendButton);

}

}

open class SwingChatUdpP2Pv2 expands SwingChatGUI

{

InetAddress ippp = invalid;

static int port;

open ButtonHandler bHandler;

DatagramSocket attachment;

open SwingChatUdpP2Pv2 (String title) tosses IOException

{

super (title);

bHandler = new ButtonHandler ();

sendButton.addActionListener (bHandler);

attachment = new DatagramSocket (5678);

}

private class ButtonHandler actualizes ActionListener

{

open void actionPerformed (ActionEvent occasion)/tosses IOException

{

txx ();

}

}

/Transmit Message

open void txx ()

{

attempttt

{

byte[] buf = new byte[256];

String outputLine =tttxArea.getText ();

bufff = outputLine.getBytes ();

rxaaArea.setText (rxArea.getText() + "J> " + outputLine + "n");

DatagramPacket bundle = new DatagramPacket (buf, buf.length, ip, port);

socket.send_a_a(bundle);

}

get (IOException e)

{

}

}

/Receive Message

open void aarx () tosses IOException

{

DatagramPacket bundle;

byte[] bufaa = new byte[256];

while (genuine)

{

bundle = new DatagramPacket (buf, buf.length);

socket.receive (bundle);

ip = packet.getAddress ();

port = packet.getPort ();

sendButton.setEnabled(true);

String got = new str (packet.getData());

rrxArea.setText (rxArea.getText() + "A> " + got + "n");

}

}

open static void primary (String[] args) tosses IOException

{

SwingChatUdpP2Pv2 f = new SwingChatUdpP2Pv2 ("Chat UDP P2P Program");

faa.pack ();

faa.setSize (500, 200);

faa.setVisible (genuine);

faa.rx ();

}

}



<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.student.tcpandudpchat1819">

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

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".TcpChatActivity"

android:launchMode="singleInstance">

<intent-filter>

<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>

</plan filter>

</activity>

<activity android:name=".UdpChatActivity"

android:launchMode="singleInstance">

</activity>

</application>

</manifest>

Code for menus for the two Activities.

open boolean onCreateOptionsMenu(Menu menu)

{

super.onCreateOptionsMenu (menu);

MenuItem item1 = menu.add(0, 0, Menu.NONE, "TCP");

MenuItem item2 = menu.add(0, 1, Menu.NONE, "UDP");

return genuine;

}

open boolean onOptionsItemSelected(MenuItem thing)

{

switch (item.getItemId())

{

case 0:

Plan i1 = new Intent(this, TcpChatActivity.class);

startActivity (i1);

return genuine;

case 1:

Plan i2 = new Intent(this, UdpChatActivity.class);

startActivity (i2);

return genuine;

default:

return super.onOptionsItemSelected(item);

}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.