View RSS Feed

Network Programming

  1. Socket Programming (Server)

    by , 11-09-2011 at 06:14 PM (My Java Tips)
    Socket programming is easy and fun. In this post, I will create a simple Socket Server that will listen on a post for client requests. It will get data from the client and will send the acknowledgment.


    First step is to declare a server socket, a client socket and input/output streams. I assume that you are familiar with streams. Then we have to open a connection on a port. Usually it is not a wise decision to use port number that is less than 1023 because ports less than 1023 are ...

    Updated 11-09-2011 at 06:28 PM by Java Tip

    Categories
    Network Programming
  2. Socket Programming (Client)

    by , 11-09-2011 at 06:04 PM (My Java Tips)
    I will write a simple socket client, that will connect to the server, send data to the server and well get connection time stamp from the server.


    In the example below, you will learn how to connect to a socket server and how to send and receive data.

    First part is to declare client socket and input/output streams. Then we have to connect to the server using socket. While declaring socket object, we have to mention the host name and the port on which the server is listening. ...
    Categories
    Network Programming
  3. TCP IP Using Socket Programming

    by , 11-08-2011 at 07:46 PM (My Java Tips)
    TCP is a connection-oriented protocol that addresses numerous reliability issues to provide a reliable byte stream. It ensures that the data arrives in-order, duplicate data is discarded and lost/discarded packets are re-sent. It includes traffic congestion control meaning that if there is too much traffic on the network, appropriate measures are taken which include telling the transmitting hosts to slow down the rate at which the data is being sent out and telling the receiving hosts to increase ...
  4. Creating UDP Server And Client

    by , 11-08-2011 at 06:29 PM (My Java Tips)
    UDP stands for User Datagram Protocol.

    UDP does not ensure reliable delivery of all the packets, the order in which the packets would be received and it is connectionless too.

    Despite all these UDP provides quick transfer of packets through low-overhead because of an minimal error-checking and correction.




    Java supports UDP through two classes.

    java.net.DatagramPacket
    contains a wrapper for an array of ...
    Categories
    Network Programming
  5. java.net.InetAddress example

    by , 11-03-2011 at 01:15 PM (My Java Tips)
    Each computer on internet is called a node or a host. Each host has unique address called Internet Protocol (IP) address. IP addresses are not easy for the humans to remember therefore, Domain Name System (DNS) was introduced. DNS assigns a human understandable name to IP addresses.




    InetAddress class represents IP addresses which can be useful in networking environment. Let see what we can o with this one:

    Following code finds and prints the IP address ...
  6. Testing supported protocols

    by , 11-03-2011 at 01:13 PM (My Java Tips)
    Consider the following scenario: You are asked to test your browser with a list of protocols. So, you can do this by making URL objects for a host with each protocol. If object is created, it means protocol is supported, in other case, it simply means that the browser does not support the particular protocol.




    Review the applet code below:

    Java Code:
    public class ProtocolTesterApplet extends Applet {
    
      TextArea results = new TextArea(
    ...
    Categories
    Network Programming
  7. Broken Pipe - Transaction

    by , 10-31-2011 at 05:51 PM (My Java Tips)
    I assume that you are having a J2EE environment with connection pool and you are using hibernate.


    When you use transactions, you have to explicitly commit or rollback every time. Some programmers believe that queries do not have to be committed. This is not right in my opinion. If you do not commit, the connection is left assigned. Which means we have dangling connections that later will be killed by the database server like: MySQL. Connection pool would later attempt to reattach ...