Solved

java network programming

Posted on 2003-11-16
5
165 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Internet options/Settings 1 62
Cisco Edge Routers for BGP 6 91
Legal Discovery - Export Keywords to PST 2 49
Application timeout 4 35
#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
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…

679 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