java tcp client and server
<p>I have the following host</p>

<pre><code>package clserver;

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 java.util.Scanner;


public class Main {
//instance vars
static ServerSocket sSocket = null;
static int serverPort = 0;
static Socket cSocket = null;
static PrintWriter out = null;
static BufferedReader in = null;


public static void main(String[] args) throws IOException {
        System.out.println("\n\n\nTCP Server Client\n\nEnter port number:");
        Scanner scan = new Scanner(System.in);
        serverPort = scan.nextInt();
        try {
            //connect server to port
            sSocket = new ServerSocket(serverPort);
        } catch (IOException ex) {
            System.err.println("That port is busy");
        }
        try {
            //accept client connection
            cSocket = sSocket.accept();
        } catch (IOException ex) {
            System.err.println("Connection failed");
        }

        out = new PrintWriter(cSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(cSocket.getInputStream()));

        System.out.println(in.readLine());

      }
}
</code></pre>

<p>and this client code</p>

<pre><code>package clclient;

import java.io.*;
import java.net.*;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Main {

    //instance vars
    static Socket cSocket =null;
static PrintWriter out = null;
static BufferedReader in = null;

//server info
static String serverName = null;
static int serverPort = 0;


public static void main(String[] args) {
    try {
        System.out.println("\n\n\nTCP Chat Client\nEnter server name:");
        Scanner scan = new Scanner(System.in);
        //get server info from user
        serverName = scan.nextLine();
        System.out.println("\nEnter port number:");
        serverPort = scan.nextInt();
        //make connection to server
        cSocket = new Socket(serverName, serverPort);
        out = new PrintWriter(cSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(cSocket.getInputStream()));
    } catch (UnknownHostException ex) {
        System.err.println("\ncan't find that host\n");

    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    String nm = "testing";
    out.print(nm);


}
</code></pre>

<p>}</p>

<p>I am trying to send messages back and forth between them but when I send a message the host crashes. It throws the exception Java.net.SocketException:connection reset</p>
