Question

can anyone show me how to Use the java.net.ServerSocket class to open a port and listen...

can anyone show me how to Use the java.net.ServerSocket class to open a port and listen for new connections ( Use the java.net.ServerSocket.accept() method to accept a new client connection. You can read from and write to the data streams in java.net.ServerSocket.getOutputStream() and java.net.ServerSocket.getInputStream() just as if they were files or standard input/outpu

Homework Answers

Answer #1

public class Server {

   private static final int port = 1313;
   public static void main(String[] args) throws IOException, AWTException {
       ServerSocket server = null;
       try {
           //opeing the port and listening connections
           server = new ServerSocket(port);
           System.out.println("Server socket ready on port: " + port);
       } catch (IOException e) {
           System.err.println("Could not listen on port: " + port);
           System.out.println(e);
           System.exit(-1);
       }
           Socket socket = null;
           try {
               //ready to accept the connections
               socket = server.accept();
               DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
               //sending hello to the connected clients
               dout.writeUTF("Hello..");
               dout.flush();
           } catch (Exception e) {
               server.close();
               e.printStackTrace();
           }
   }
}

Note : If you like my answer please rate and help me it is very Imp for me

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need...
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need to write a client program and a server program for this question to be correct. ** **Cannot use socket** client the client application that will get the command from the user and pass the command to be executed from the command line, parses the command and puts a binary representation of the parse into a shared memory segment. At this point, the client will...
Hi, can you make me rotate method for this class just I need rotate method? this...
Hi, can you make me rotate method for this class just I need rotate method? this is Circularly Linked Lists code. public class Node {    int data;    Node next;    public Node(int data) {        this.data = data;    } } // this is implement class public class CircularLinkList {       public int size = 0;    public Node head = null;    public Node tail = null;       // add to the front of...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
In the book_store.cpp file, add the code for the process_orders method. The argument that is passed...
In the book_store.cpp file, add the code for the process_orders method. The argument that is passed to this method is the name of a file that will be read in the method. Each line in the file contains an order number (integer), isbn number (character array), and amount ordered (integer). If an order number is on a line, it is guaranteed that there will be an isbn number and amount ordered to go along with it. Create an input file...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
1.What is the difference between class/object? 2.Did you think about classes/objects around you since the last...
1.What is the difference between class/object? 2.Did you think about classes/objects around you since the last session? 3.What library do we need for processing file I/O? 4.What is the class for the input file stream? Give an example 5.What is the class for the output file stream? Give an example 6.Why do you want to use files instead of using input? 7.How do you read from a file? give an example 8.How do you write to a file? give an...
Can someone please show me how to find out the answer to this? Consider the following...
Can someone please show me how to find out the answer to this? Consider the following data representing the price of refrigerators (in dollars). 14051405, 11211121, 13391339, 10961096, 12991299, 14011401, 11381138, 11491149, 12231223, 10711071, 13991399, 14001400, 12421242, 13181318, 11011101, 10651065, 14281428, 12251225, 13501350, 13581358, 13121312 Copy Data Price of Refrigerators (in Dollars) Class Frequency Class Boundaries Midpoint Relative Frequency Cumulative Frequency 1049–1118 1119–1188 1189–1258 1259–1328 1329–1398 1399–1468 Step 2 of 7 :   Determine the frequency of the fifth class.
Can you show me how to do this using Excel? Suppose we gathered the data below...
Can you show me how to do this using Excel? Suppose we gathered the data below by an unbiased method.  (The data is sorted DOWN the columns.) 111 116 119 120 123 126 128 131 136 142 115 117 119 120 123 127 129 132 136 142 115 117 120 121 123 127 129 133 138 143 115 118 120 121 123 128 131 133 138 158 116 118 120 123 125 128 131 135 141 163 (4 pts) Use the...
Hello can someone show me how to incorporate my method integerPower into the main? I want...
Hello can someone show me how to incorporate my method integerPower into the main? I want it to be able to take in the values the user inputs and calculate the value. here is the code I have so far: { public static void main(String[] args) { Scanner input = new Scanner(System.in); int base; int exponent; System.out.printf("Enter base value: ");    base = input.nextInt();    System.out.printf("Enter the exponent value:");    exponent = input.nextInt(); } public static int integerPower(int base, int...
I can open the file in the program, but I cannot figure out how to properly...
I can open the file in the program, but I cannot figure out how to properly split the data and assign a grade to the number values in the text file. I keep getting :: ValueError: invalid literal for int() with base 10: 'Roger Jones 75\n' Below are the assignment details: This program processes grades for a small class. It reads an input file named grade_input.txt where each record contains a student’s first name, last name and numeric grade (a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT