Solved

java network programming

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

623 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