Solved

java network programming

Posted on 2003-11-16
5
160 Views
Last Modified: 2010-04-11
hi,

i want to implement a chord (peer to peer network) using java by passing files over TCP
can any1 tell me how to go about with it

thx
0
Comment
Question by:aseeml
  • 2
5 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761360
Why?
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9761362
And, why ask here instead of in the Java topic area?
0
 
LVL 16

Accepted Solution

by:
SteveJ earned 125 total points
ID: 9766424
I wrote my own (poor man's OpenView) device monitor in Java. This code opens a socket and writes data to the buffer which is then sent over the socket connection. There's quite a bit more to it than this, but using this snippet you should be able to grope around the web and cobble together what you need.

This sends some data to -- for example -- port 80 on a machine called host_name using a process called "wr"

InetAddress waddr = InetAddress.getByName(host_name);
int wport = 80;
SocketAddress wsock = new InetSocketAddress(waddr, wport);
Socket w_sock = new Socket();
int TimeoutMs = 3000;
w_sock.connect(wsock, TimeoutMs);
w_sock.setSoTimeout(TimeoutMs);
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(w_sock.getOutputStream()));
String hd = new String(somedata);
wr.write(hd);
wr.flush();


This reads a bufferto see if there's anything there . . . to read . . . assuming that wsilen is greater than 0

BufferedReader wsi = new BufferedReader(new InputStreamReader(w_sock.getInputStream()));
wsimsg = wsi.readLine();
wsilen = wsimsg.length();

I am not a programmer and someone in the Java session would look at this code and agree. But if you just want to write data back and forth between machines to learn about sockets programming in Java this will help you get started . . .

Go to http://java.sun.com/docs/books/tutorial . . . Network Programming.

Good luck,
Steve
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Backup UPS - email alert 3 85
OSPF Design NSSA 5 34
Network Connection 5 34
ethernet cat5e lenght 80m 9 35
Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now