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 .. - import java.net.*;
-
import java.io.*;
-
public class lab1_Qu2 {
-
-
/**
-
* @param args
-
*/
-
public static void main(String[] args) {
-
// TODO Auto-generated method stub
-
try{
-
System.out.println("chat started........");
-
chat cht=new chat();
-
cht.create_socket("localhost",135);
-
System.out.println("chat Ended........");
-
}
-
-
catch(IOException e){
-
System.err.println(e.getMessage());
-
}
-
-
}
-
-
-
-
}
-
-
-
class chat{
-
-
//method to create socket
-
public void create_socket(String host,int port_num) throws IOException {
-
-
PrintWriter pW=null;
-
Socket hello_sck=new Socket(host,port_num);
-
send_hello("Hello",hello_sck,pW);
-
hello_sck.close();
-
-
-
}
-
-
//Method to send Hello text
-
public void send_hello(String str,Socket echoSocket,PrintWriter pW){
-
try
-
{
-
-
pW = new PrintWriter(echoSocket.getOutputStream(), true);
-
create_stream(echoSocket);
-
pW.print(str);
-
}
-
catch(IOException e)
-
{
-
System.err.println(e.getMessage());
-
}
-
}
-
-
-
//method to create stream
-
public void create_stream(Socket echoSocket) throws IOException{
-
BufferedReader in
-
= new BufferedReader(
-
new InputStreamReader(
-
echoSocket.getInputStream()));
-
PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
-
out.flush();
-
System.out.println("Socket input started..1");
-
while (true) {
-
System.out.println("Socket input started..2");
-
String str = in.readLine();
-
if (str == "exit") {
-
System.out.println("Socket input started..3");
-
break;
-
} else {
-
System.out.println("Socket input started..4");
-
System.out.println(str);
-
}
-
}
-
System.out.println("Socket input started..5");
-
-
}
-
}
-
-
-
-
-
-
-
-
-
import java.net.*;
-
import java.io.*;
-
public class lab1_Qu2_server {
-
-
/**
-
* @param args
-
*/
-
public static void main(String[] args) {
-
// TODO Auto-generated method stub
-
lab1_Qu2_server server_app1=new lab1_Qu2_server();
-
server_app1.chat_server();
-
}
-
-
public ServerSocket create_server(int port)throws IOException {
-
return new ServerSocket(port);
-
}
-
-
public Socket create_client(ServerSocket s) throws IOException{
-
return s.accept();
-
}
-
-
public void create_stream(Socket clientSocket) throws IOException{
-
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
-
BufferedReader in = new BufferedReader(
-
new InputStreamReader(
-
clientSocket.getInputStream()));
-
-
send_hello("Hello back",out);
-
out.flush();
-
-
}
-
-
private void send_hello(String str,PrintWriter p){
-
p.println(str);
-
-
}
-
-
public void chat_server(){
-
try
-
{
-
ServerSocket server=create_server(3003);
-
Socket client=create_client(server);
-
create_stream(client);
-
-
-
}
-
catch(IOException e)
-
{
-
System.err.println(e.getMessage());
-
}
-
-
}
-
-
}
-
These are my server and client side codes.Just go through them and tell me what's wrong...
With regards
1 2467
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |