Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Sockets and Internet Protocols
adapting client code example
Bob Matthews
Rancher
Posts: 688
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I have the following example code.................
import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; public class SocketClient { public static void main(String[] args) { try { InetAddress host = InetAddress.getLocalHost(); Socket socket = new Socket(host.getHostName(), 7001); ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream()); outputStream.writeObject("SELL"); ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream()); String message = (String) inputStream.readObject(); System.out.println("Message: " + message); inputStream.close(); outputStream.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
How do I incorporate this code into an existing program which does a whole lot of stuff before I need to send a message ?
Bob M
A.J. Côté
Ranch Hand
Posts: 417
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Just copy and paste the code from line 11 to 27 inclusively and import the relevant classes in your code.
I hadn't been here for fifteen years
Bob Matthews
Rancher
Posts: 688
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you A J
So simple
Bob M
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
SocketPermission
Application Client-Server and stream
how to get system information
Threads and global variable prolems
File transfer from Client to Server side
More...