hi,
i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java.
i am putting that program here now,
Server.java Program:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args) throws IOException{
Socket client= null;
PrintWriter pout=null;
ServerSocket sock=null;
try{
sock= new ServerSocket(51 55);
// now listen for connections
while(true){
client= sock.accept();
// we have a connection
pout = new PrintWriter(cli ent.getOutputSt ream(), true);
// write the date to the socket
pout.println(ne w java.util.Date( ).toString());
pout.close();
client.close();
}
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally {
if (client !=null)
client.close();
if (sock !=null)
sock.close();
}
}
Client.java Program:
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String[] args) throws IOException{
InputStream in = null;
BufferedReader bin = null;
Socket sock = null;
try {
// make connection to socket
sock = new Socket("127.0.0 .1",5155);
in = sock.getInputSt ream();
bin = new BufferedReader( new InputStreamRead er(in));
String line;
while ((line= bin.readLine()) !=null)
System.out.prin tln(line);
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally{
if (sock !=null)
sock.close();
}
}
}
tell me wat shud i change in this program?
is it correct doing this?
Help me in doing this?
its urgent
}
4 2135
hi,
i just want 2 communicate with the near by computer. i got this program from internet. i have two programs called Server.java and Client.java.
i am putting that program here now,
Server.java Program:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args) throws IOException{
Socket client= null;
PrintWriter pout=null;
ServerSocket sock=null;
try{
sock= new ServerSocket(51 55);
// now listen for connections
while(true){
client= sock.accept();
// we have a connection
pout = new PrintWriter(cli ent.getOutputSt ream(), true);
// write the date to the socket
pout.println(ne w java.util.Date( ).toString());
pout.close();
client.close();
}
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally {
if (client !=null)
client.close();
if (sock !=null)
sock.close();
}
}
Client.java Program:
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String[] args) throws IOException{
InputStream in = null;
BufferedReader bin = null;
Socket sock = null;
try {
// make connection to socket
sock = new Socket("127.0.0 .1",5155);
in = sock.getInputSt ream();
bin = new BufferedReader( new InputStreamRead er(in));
String line;
while ((line= bin.readLine()) !=null)
System.out.prin tln(line);
}
catch (IOException ioe) {
System.err.prin tln(ioe);
}
finally{
if (sock !=null)
sock.close();
}
}
}
tell me wat shud i change in this program?
is it correct doing this?
Help me in doing this?
its urgent
}
This program is correct!
At first you must compile and run Server class and than Client
it is throwing me ConnectionExcep tion error
i dont no wat 2 do 4 this?
hiiii,
where shud i compile this?
Computer1: server.java
Computer2: Client.java. In this i am giving the IP address of that Server.
In which computer i shud compile this?
tell me . its urgent.
You must look there must be same port (number), and same IP address to connect ot server. I'll give you another version. I have Net3.java and Net4.java. And I'll bring tomorrow.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities as a standard
portable part of the core language, the LISP package, and the java.lang
package, respectively. Both have big integers, although only LISP has
rationals as far as I can tell. Because CL supports keyword arguments,
it has a wider range...
|
by: Nuno Silva |
last post by:
Hello,
I'm starting to learn about java networking.
What I want to do is for now, just make a server that listens to connections
through a port, and accepts it's connections from the client.
I don't have that many connections about networking, so I don't know any
good book that gives a nice comprehensive introduction to java networking.
|
by: DrUg13 |
last post by:
In java, this seems so easy. You need a new object
Object test = new Object() gives me exactly what I want.
could someone please help me understand the different ways to do the
same thing in C++. I find my self sometimes, trying
Object app = Object();
Object *app = Object();
Object app = new Object();
|
by: somebody |
last post by:
No, I'm not a troll, just angry. I just started learning
C++, and find it extremely lacking compared to Java.
For example, I had to write my own functions to do something
as simple as a case insensitive string comparison, and a
substring search. Then I found that there are no networking
classes to speak of (except sockets). After I thought about
it, C++ really pales by comparison. Java has a rich set of
networking classes, regular...
|
by: s0suk3 |
last post by:
I've been programming Python for a couple of years now. Now I'm
looking to move on to either C++ or Java, but I'm not sure which.
Which one do you think will be a better transition for a Python
programmer? Which one will educate me the best?
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |