Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

writing data form server socket to client socket

Thread view: 
greatestmclarenfan - 16 Feb 2006 04:40 GMT
I have a program which acts as both a server and a client.
I have to read data from the the server socket, process the first few
lines, and then write the remaining data to a client socket. This data
may contain images.

Can you tell me the quickest/efficient way of doing this? I would like
to avoid reading/writing data bit by bit.

Thanks,
Swapnil.
ebby83@gmail.com - 16 Feb 2006 06:14 GMT
use BufferedReader and PrintWriter classes , open 2 connections of each
, one each to the origin and one to the destination ... cross link both
of them and ur done ..

r1 , r2
w1 , w2

String line;
while ( !(line=r1.readLine() ).equals(null) ) {
    w2.write(line);
}

// do something

while ( !(line=r2.readLine() ).equals(null) ) {
    w1.write(line);
}
Steve Horsley - 16 Feb 2006 20:05 GMT
> use BufferedReader and PrintWriter classes , open 2 connections of each
> , one each to the origin and one to the destination ... cross link both
[quoted text clipped - 13 lines]
>      w1.write(line);
> }

No. That will totally corrupt any binary data like image files.
You must use InputStream and OutputStream. These have
read(byte[]) and write(byte[]) methods. Use a byte[] of 1600
bytes and you should get good performance.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.