Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

java network programming

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
aseeml
Asked:
aseeml
  • 2
1 Solution
 
qwaleteeCommented:
Why?
0
 
qwaleteeCommented:
And, why ask here instead of in the Java topic area?
0
 
SteveJCommented:
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

New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now