Solved

java network programming

Posted on 2003-11-16
5
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

752 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