A single java program to receive and send plain text through differen ports.
I have programmed a Router class which has two methods, receive and send.In receive method it receives the plain text from the server through port 2000.Its now all cool.In send method it sends the message to a client through the port 2001 but at the client i get an exception
Code :
connection refused:connect
Code :
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;
class Router
{
String str;
public void receive()
{
try
{
while(true)
{
Socket so=new Socket("localhost",2000);
BufferedReader br=new BufferedReader(new InputStreamReader(so.getInputStream()));
str=br.readLine();
System.out.println("server has sent:"+str);
so.close();
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void send()
{
int i,index,min=100;
int row=2;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:DSN2");
Statement st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=st.executeQuery("select * from Table1");
//rs.absolute(row);
rs.next();
rs.next();
//System.out.println(rs.getInt(1)+"\t"+rs.getInt(2)+"\t"+rs.getInt(3)+"\t"+rs.getInt(4)+"\t"+rs.getInt(5)+"\t"+rs.getInt(6));
for( i=2;i<7;i++)
{
int value=rs.getInt(i);
System.out.println("hello");
if(value<min)
{
index=i;
min=value;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class Router1
{
public static void main(String s[])
{
Router obj=new Router();
obj.receive();
obj.send();
}
}
Re: A single java program to receive and send plain text through differen ports.
I don't see a ServerSocket class in the posted code. Where is the code for the server?
Re: A single java program to receive and send plain text through differen ports.
Quote:
Originally Posted by
Norm
I don't see a ServerSocket class in the posted code. Where is the code for the server?
Yes I dint post the Server program.But i have programmed it correctly itself.I got the solution as the Client was trying to read from the Stream which is closed already in the server program.
Re: A single java program to receive and send plain text through differen ports.
Quote:
the Stream which is closed already in the server program.
That is why I asked to see the server code.
Glad you got it working.