473,473 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Server and Log File

James Bond
12 New Member
Hi there
I am developing a client/server app in Java. I have created a client and a server
via the java.net package. But now i want that ach time the client logs on to the server, a log file is created.

For this i created another class that is used only to read data from the cilent socket and implemented runnable in this class.

Now this reading class is called "SocketReader", and is coded as follows:

import java.io.*;
import java.net.*;

public class socketReader implements Runnable{

BufferedReader readMessage;
String message="";

synchronized String socketReader(Socket client){
Thread t=new Thread(this);
t.start();

public void run(){
try{


//while(true){
readMessage=new BufferedReader(new InputStreamReader
(client.getInputStream()));
message=readMessage.readLine();
readMessage.close();
//}
}
catch (IOException ioex){
System.out.println("Exception: "+ioex);
}
} // run () ends here
return message;
} // constructor ends here
} // class ends here

The problem is that it gives an error message.
Wats going wrong. i've even tried to declare the run() outside the constructor.
Kindly reply
Jan 24 '07 #1
11 1881
r035198x
13,262 MVP
Hi there
I am developing a client/server app in Java. I have created a client and a server
via the java.net package. But now i want that ach time the client logs on to the server, a log file is created.

For this i created another class that is used only to read data from the cilent socket and implemented runnable in this class.

Now this reading class is called "SocketReader", and is coded as follows:

import java.io.*;
import java.net.*;

public class socketReader implements Runnable{

BufferedReader readMessage;
String message="";

synchronized String socketReader(Socket client){
Thread t=new Thread(this);
t.start();

public void run(){
try{


//while(true){
readMessage=new BufferedReader(new InputStreamReader
(client.getInputStream()));
message=readMessage.readLine();
readMessage.close();
//}
}
catch (IOException ioex){
System.out.println("Exception: "+ioex);
}
} // run () ends here
return message;
} // constructor ends here
} // class ends here

The problem is that it gives an error message.
Wats going wrong. i've even tried to declare the run() outside the constructor.
Kindly reply
Please use code tags next time when posting code.
Do not put the run method inside the constructor.
What error message do you get when you have the run method outside the constructor?
Jan 24 '07 #2
James Bond
12 New Member
Please use code tags next time when posting code.
Do not put the run method inside the constructor.
What error message do you get when you have the run method outside the constructor?
Thanks for replying!!
The error msg that i recieve is that:
illegal start of expression in public void run(). It points on the public.
Jan 24 '07 #3
r035198x
13,262 MVP
Thanks for replying!!
The error msg that i recieve is that:
illegal start of expression in public void run(). It points on the public.
Sorry for the delay, I'd got disconnected. Post the code that you have that has the run method outside the constructor

Remember the code tags.
Jan 24 '07 #4
r035198x
13,262 MVP
You might want to have a look at this thread too.
Jan 24 '07 #5
James Bond
12 New Member
You might want to have a look at this thread too.
Thanks for replying again.
GOOD NEWS : I got the class compiled.
The mistake i was doing was that i wasnt passing the value of the argument of the constructor to a local instance variable. and it was giving me an error msg "Go Hang Yourself".
But now i have made that change. The New code looks like this:



Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. public class socketReader implements Runnable{
  5.  
  6.     BufferedReader readMessage;
  7.     String message="";
  8.     Socket client;
  9.  
  10.     synchronized String socketReader(Socket client){
  11.  
  12.         this.client=client;
  13.         Thread t=new Thread(this);        
  14.         t.start();
  15.  
  16.         return message;                    
  17.     }
  18.  
  19.  
  20.  
  21.         public void run(){
  22.             try{
  23.  
  24.  
  25.                 //while(true){
  26.                 readMessage=new BufferedReader(new InputStreamReader(client.getInputStream()));
  27.                 message=readMessage.readLine();
  28.                 readMessage.close();
  29.                 //}                        
  30.             }
  31.             catch (IOException ioex){
  32.                 System.out.println("Exception: "+ioex);
  33.             }
  34.         }
  35.  
  36. }
and another thing : I couldnt understand wat u were saying abt using tags.
Jan 25 '07 #6
r035198x
13,262 MVP
Thanks for replying again.
GOOD NEWS : I got the class compiled.
The mistake i was doing was that i wasnt passing the value of the argument of the constructor to a local instance variable. and it was giving me an error msg "Go Hang Yourself".
But now i have made that change. The New code looks like this:





and another thing : I couldnt understand wat u were saying abt using tags.
When making a post look at the right side of the page where it says reply guidelines and the third point there is talking about wrapping the code you post in code tags. I will now edit the code you just posted to include these tags and you can see what I'm talking about.
Jan 25 '07 #7
James Bond
12 New Member
When making a post look at the right side of the page where it says reply guidelines and the third point there is talking about wrapping the code you post in code tags. I will now edit the code you just posted to include these tags and you can see what I'm talking about.
Expand|Select|Wrap|Line Numbers
  1. Thanks I got it.
Jan 25 '07 #8
James Bond
12 New Member
Expand|Select|Wrap|Line Numbers
  1. Thanks I got it.
Did u notice that i have declared the constructor of the class as Synchronized.
This was because i want either the server or the log file to access the data from the client at one time.

Can u suggest me wat would i have to do when multiple clients log on to the sever.
Regards
Jan 25 '07 #9
r035198x
13,262 MVP
Did u notice that i have declared the constructor of the class as Synchronized.
This was because i want either the server or the log file to access the data from the client at one time.

Can u suggest me wat would i have to do when multiple clients log on to the sever.
Regards
Oh dear.
1)That is not a constructor according to the compiler. Constructors do not return anything. Your method there returns a string.
2.)For the use of synchronized, you should have a look at a threads tutorial before you start using that.
Jan 25 '07 #10
James Bond
12 New Member
Thanks for really bright suggestions.

I want to ask u a very important question. I dont have an idea regarding how i can detect a hardware attached to my system through a java programe.

Acctually i want to detect a GSM modem through my programme so that my system becomes a server and the mobile cell phones can access its database
by sending a message to my server.

Please reply
Rgds.
Jan 27 '07 #11
James Bond
12 New Member
Thanks for really bright suggestions.

I want to ask u a very important question. I dont have an idea regarding how i can detect a hardware attached to my system through a java programe.

Acctually i want to detect a GSM modem through my programme so that my system becomes a server and the mobile cell phones can access its database
by sending a message to my server.

Please reply
Rgds.
Jan 28 '07 #12

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

Similar topics

2
by: Phil | last post by:
I am using a Pascal like language (Wealth-Lab) on W2K and call this server: class HelloWorld: _reg_clsid_ = "{4E797C6A-5969-402F-8101-9C95453CF8F6}" _reg_desc_ = "Python Test COM Server"...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
6
by: john_williams_800 | last post by:
Hi; I am writing an html page that will live on one server in an ms windows network, but access pictures from a directory on another ms windows server in the network. I know in html the...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
4
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
0
by: lknight643 | last post by:
I have an asp.net application that works with a SQL server database on server No. 1 but I want to upload files for storage to Server No. 2 that is accessible only from the Internet. If the file...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: manish deshpande | last post by:
Hi, When i'm installing MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm by the following command: rpm -i MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm the following error is being shown: ...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.