Hello Joe,
When I type the external IP address , it works only on my browser. Other computers on the internet are not able to access it. Also my client Socket is not able to access it when I set the IP address to the external IP.
I am pasting my socket programs.
Client Side.
import java.net.*;
import java.io.*;
public class trialClient
{
public static final int SERVER_PORT=80;
public static void main(
String[] args) throws IOException
{
//check for validity of args[0] here.
InetAddress addr = InetAddress.getByName("59.92.243.151"); //--------comment1
System.out.println("addr = " + addr);
Socket socket = new Socket(addr,SERVER_PORT);
// Guard everything in a try-finally to make
// sure that the socket is closed:
try
{
System.out.println("socket = " + socket);
BufferedReader in = new BufferedReader( new InputStreamReader(
socket.getInputStream()));
// Output is automatically flushed
// by PrintWriter:
System.out.println("coming....1");
PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream())),true);
System.out.println("coming....2");
for(int i = 0; i < 10; i ++)
{
out.println("howdy " + i);
String str = in.readLine();
System.out.println("The msg frm server is :"+str);
}
out.println("END");
System.out.println("coming....3");
}
finally
{
System.out.println("closing...");
socket.close();
}
}
}
Server Side
import java.io.*;
import java.net.*;
public class trialServer
{
// Choose a port outside of the range 1-1024:
public static final int PORT = 80;
public static void main(String[] args) throws IOException
{
ServerSocket s = new ServerSocket(PORT);
System.out.println("Started: " + s);
try
{
// Blocks until a connection occurs:
Socket socket = s.accept();
try
{
System.out.println( "Connection accepted: "+ socket);
BufferedReader in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
// Output is automatically flushed by PrintWriter:
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(
socket.getOutputStream())),true);
while (true)
{
String str = in.readLine();
if (str.equals("END"))
break;
System.out.println("Echoing: " + str);
out.println(str);
}
// Always close the two sockets...
}
finally
{
System.out.println("closing...");
socket.close();
}
}
finally
{
s.close();
}
}
}
I am opening 2 seperate Dos Windos n run client n server seperately.
1)When I set the ip address at <Comment1> to 192.168.1.2 the program works fine
2. When I set the ip addres at <comment1> to the dynamic ip at that particular moment ,
The server side socket doesnt recive the message sent by client.Also the client program terminates , it recieves a 'bad request' from the server.
HTTP 1.1 /400 bad request
Could you tell me what actually is happening and where am I going wrong?
Thanks
Sandeep