473,419 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Why is my server not responding?

108 100+
Here's a little script I just implemented with ref to internet ..i run my server and then my client..
On my client side i input some string into my client side I am su[pposed to get a hello back from the server...This part is not working ..


Expand|Select|Wrap|Line Numbers
  1. import java.net.*;
  2. import java.io.*;
  3. public class lab1_Qu2 {
  4.  
  5.     /**
  6.      * @param args
  7.      */
  8.     public static void main(String[] args) {
  9.         // TODO Auto-generated method stub
  10.         try{
  11.             System.out.println("chat started........");
  12.             chat cht=new chat();
  13.             cht.create_socket("localhost",135);
  14.             System.out.println("chat Ended........");
  15.         }
  16.  
  17.         catch(IOException e){
  18.             System.err.println(e.getMessage());
  19.         }
  20.  
  21.     }
  22.  
  23.  
  24.  
  25. }
  26.  
  27.  
  28. class chat{
  29.  
  30.     //method to create socket
  31. public void create_socket(String host,int port_num) throws IOException {
  32.  
  33.     PrintWriter pW=null;
  34.         Socket  hello_sck=new Socket(host,port_num);
  35.         send_hello("Hello",hello_sck,pW);
  36.         hello_sck.close();
  37.  
  38.  
  39.     }
  40.  
  41.     //Method to send Hello text
  42.     public void send_hello(String str,Socket echoSocket,PrintWriter pW){
  43.         try
  44.             {    
  45.  
  46.             pW = new PrintWriter(echoSocket.getOutputStream(), true);
  47.                 create_stream(echoSocket);
  48.                 pW.print(str);
  49.             }
  50.         catch(IOException e)
  51.             {
  52.                 System.err.println(e.getMessage());
  53.             }
  54.     }
  55.  
  56.  
  57.     //method to create stream
  58.     public void create_stream(Socket echoSocket) throws IOException{
  59.         BufferedReader in
  60.         = new BufferedReader(
  61.         new InputStreamReader(
  62.         echoSocket.getInputStream()));
  63.         PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
  64.         out.flush();
  65.         System.out.println("Socket input started..1");
  66.         while (true) {
  67.             System.out.println("Socket input started..2");
  68.             String str = in.readLine();
  69.             if (str == "exit") {
  70.                 System.out.println("Socket input started..3");
  71.             break;
  72.             } else {
  73.                 System.out.println("Socket input started..4");
  74.             System.out.println(str);
  75.             }
  76.             }
  77.         System.out.println("Socket input started..5");
  78.  
  79.     }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. import java.net.*;
  90. import java.io.*;
  91. public class lab1_Qu2_server {
  92.  
  93.     /**
  94.      * @param args
  95.      */
  96.     public static void main(String[] args) {
  97.         // TODO Auto-generated method stub
  98.         lab1_Qu2_server server_app1=new lab1_Qu2_server();
  99.         server_app1.chat_server();
  100.     }
  101.  
  102.     public ServerSocket create_server(int port)throws IOException {
  103.         return new ServerSocket(port);
  104.     }
  105.  
  106.     public Socket create_client(ServerSocket s) throws IOException{
  107.         return s.accept();
  108.     }
  109.  
  110.     public void create_stream(Socket clientSocket) throws IOException{
  111.         PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
  112.         BufferedReader in = new BufferedReader(
  113.                 new InputStreamReader(
  114.                 clientSocket.getInputStream()));
  115.  
  116.         send_hello("Hello back",out);
  117.         out.flush();
  118.  
  119.     }
  120.  
  121.   private void send_hello(String str,PrintWriter p){
  122.       p.println(str);
  123.  
  124.   }
  125.  
  126.   public void chat_server(){
  127.       try
  128.               {
  129.                   ServerSocket server=create_server(3003);
  130.                   Socket client=create_client(server);
  131.                   create_stream(client);
  132.  
  133.  
  134.               }
  135.       catch(IOException e)
  136.               {
  137.                   System.err.println(e.getMessage());
  138.               }
  139.  
  140.   }
  141.  
  142. }
  143.  
These are my server and client side codes.Just go through them and tell me what's wrong...

With regards
Aug 17 '10 #1
1 2467
Oralloy
988 Expert 512MB
I can't say much because of teh quick look I took, but it looks like your port numbers don't match up. 135 != 3003.

Also, note that ports under 1024 are reserved for system use. Although, if you're running as admin or root, you might not care. On the other hand, you might, if you collide with a running service.

Cheers.
Aug 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alan Easton | last post by:
Hi All, I have a strange problem occuring with my ASP/MS SQL Server website. My site is totally ASP driven, powered by a MS SQL Server DB. Now for months it has worked/performed very well, no...
0
by: Michael Bourgon | last post by:
I've been having the same problem for 2 weeks now. If anyone has any ideas, I'd love to hear them. We are using both SQL and Windows Authentication. I was running a Profiler Trace at the time,...
13
by: long5120 | last post by:
I am trying to use webpage with javascript to check if a web server is responding. I was thinking of using 2 frames. Frame1 will have the site, and the Frame2 will be a status bar (not really...
2
by: Nils Hedström | last post by:
Today my stateserver (running at the same computer at the web-server) suddenly stopped responding (after 10 days working perfectly). I did not see any entry in the eventlog indicating that the...
6
by: Botak | last post by:
Hi, I wrote an app under vb.net to calculate huge data from MS Sql server. Whenever this app is running, I could not do other work. Or else, the app will become "not responding" but actually it is...
4
by: VB Programmer | last post by:
When I run my ASP.NET 2.0 web app on my dev machine it works perfect. When I precomile it to my web deployment project and then copy the debug files to my web server I get this problem when trying...
1
by: Ron | last post by:
Hi, I had a stored procedure on SQL 2000 server to run calculation with large amount of data. When I called this stored procedure via System.Data.SqlClient.SqlCommand on production, i got error...
2
by: seb | last post by:
Hi, this simple server (time protocol) does not respond after a few hours, even when it is restarted. The behaviour looks to me like a firewall blocking but I have desabled the firewall. Using...
0
by: Sinchana | last post by:
Hi All, In our .Net 2.0 Application ,we have a third party Tree Control. We are loading the Tree control nodes using a stored procedure and the tree nodes are populating perfectly.But some time...
7
by: mills.toby | last post by:
We have a Windows 2003 Server, serving an asp.net (2.0) website. Recently the website stopped responding. When trying to access the website, no response is received at all. This includes when...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.