Results 1 to 6 of 6

Thread: What is socket and server socket in java?

  1. #1
    Join Date
    Dec 2009
    Posts
    59

    What is socket and server socket in java?

    Hi friends,

    The networking concepts of java programming seems quit complicated. I am not able to get what socket ans server socket. Is socket and server socket based on same functionality?or what?. I don't know how to proceed. If you have knowledge about it , then please let me know something about the socket and server socket of java programming. Your help will be appreciable.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is socket and server socket in java?

    A Socket is a kind of anchor for the protocols of data such as TCP / IP. The Socket object is to manage two data streams: one input stream (InputStream), ensuring the receipt, and an output stream (OutputStream), to send data. In Java, we distinguish two types of Socket: single Socket (called "clients") and socket servers. A socket client is simply a socket that will connect to a socket server asking it to perform tasks.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: What is socket and server socket in java?

    Like Socket i.e the client sockets, server sockets offer an inflow and outflow. To use a socket server in Java, just use an instance of the ServerSocket class of java.net package. The ServerSocket class provides three constructors one of which concerns as:
    ServerSocket (int port)
    It lets you specify a port. But in this case, this whole define the identification number of the port to create. We are also entirely free to choose the port number when it is within the limits permitted by the int (0 to 2 147 483 647, ie 2 ^ 32 / 2 - 1 because we can only use integers)

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: What is socket and server socket in java?

    Hi friend,

    Please refer following code to understand the declaration of socket in java:
    Code:
    import java.net.*;
    import java.lang.*;
    import java.io.*;
    public class Fibbn1 {
        public static void main(String argu[]) {
                try {
                ServerSocket sSocn = new ServerSocket(2001);
                   while(true) {
                    Socket inSocn = sSocn.accept();
                     FibThread FibTn = new FibThread(inSocn);
                    FibTn.start();}
            }
            catch (Exception e) {
                System.out.println("Oh Dear! " +
                e.toString());
            }
        }
    }
    class FibThreadn extends Thread {
        Socket threadSocn;
        int Fn1 = 1;
        int Fn2 = 1;
        FibThread(Socket inSocn) {
            threadSocn = inSocn;
        }        public void run() {
            try {
                PrintStream FibOutb = new
                  PrintStream(threadSoc.getOutputStream());
                            
                for (int ib=0; ib < 100; ib++) {
                    int temp;
                    
                    temp b= Fb1;
                    FibOut.println(F1);
    
                    Fb1 = Fb2;
                    Fb2 = tempb + Fb2;
                }
            }
                      try {
                threadSocn.close();
            }
            catch (Exception e) {
                System.out.println(   e.toString());
            }
        }
    }

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is socket and server socket in java?

    The socket and server socket are quite different in java. In serverSocket you should provide the value of "port" as a arguments. All network applications using specific ports, you must be careful not to use a number already taken. If your server is intended to be used on a personal machine, it is unlikely that the use of port 25 (sending emails) or 8080 (HTTP) to be bothersome. However, this is strongly discouraged, especially since the value range allowed is more than enough for you to find your happiness. In our example we use port number 1705.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is socket and server socket in java?

    Hello friend,

    I have following java code, which will demonstrate you about how to declare and use the "socket in java":
    Code:
    import java.io.*;
    import java.net.*;
    public class FibReader
     {
        Socket appSoct;
        BufferedReader inj;
        String messaget;
        
        public static void main(String argi[]) {
            try {
                appSoct = new Socket("wherever",2001);
                inj = new BufferedReader(new InputStreamReader(appSoc.getInputStream()));
                for (int im = 0; im < 100; im++) {
                    message = inj.readLine();
                    System.out.println(messaget); }
            }
            catch (Exception e) {
                System.out.println("Died... " +   e.toString());
            }
        }

Similar Threads

  1. Replies: 6
    Last Post: 22-07-2011, 10:24 PM
  2. Socket problem in java
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 04:23 AM
  3. Which one should i buy: AMD Socket AM2 or Intel Socket 1156 ?
    By Liam M in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 24-12-2009, 11:18 AM
  4. Winsock Socket error 10048 socket bind
    By Theophilus in forum Operating Systems
    Replies: 4
    Last Post: 16-02-2009, 08:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,568,279.63281 seconds with 17 queries