Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Implementing a Client Server Model (Using TCP) and sending a IP address from server and Printing it out on Client
Post Flair (click to view more posts with a particular flair)
Post Body

Server code:

    package exp1;
    import java.net.*;
    import java.io.*;
    public class MyServerSocket{
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
              ServerSocket ss=new ServerSocket(2050); 
              System.out.println("server is waiting..."); 
              Socket s=ss.accept(); 

              InetAddress ad= InetAddress.getByName("hostname");
              OutputStream os=s.getOutputStream(); 
              System.out.println("s"  ad.getHostAddress());
              byte ins=Byte.parseByte(ad.getHostAddress());
              os.write(ins); 

              ss.close();
        }


    }

Client code:

    package exp1;
    import java.io.*;
    import java.net.*;
    public class MyClientSocket {
        public static void main(String[] args) throws Exception{
        Socket s=new Socket(InetAddress.getLocalHost(),2050); 
        InputStream is=s.getInputStream(); 
        System.out.println("Client is ready to receive data"); 
        int d=0; 
        while(d!='#') 
        { 
        d=is.read(); 
        System.out.print((char)d); 
        }        
        }
    }

Error:

Server side:

Exception in thread "main" java.lang.NumberFormatException: For input string: "ip"

at java.base/java.lang.NumberFormatException.forInputString([NumberFormatException.java:67](https://NumberFormatException.java:67))

at java.base/java.lang.Integer.parseInt([Integer.java:660](https://Integer.java:660))

at java.base/java.lang.Byte.parseByte([Byte.java:193](https://Byte.java:193))

at java.base/java.lang.Byte.parseByte([Byte.java:219](https://Byte.java:219))

at exp1/exp1.MyServerSocket.main([MyServerSocket.java:14](https://MyServerSocket.java:14))

Author
Account Strength
90%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,605
Link Karma
336
Comment Karma
3,127
Profile updated: 5 days ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago