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
Tim Cooke
Ron McLeod
paul wheaton
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Himai Minh
Bartenders:
Forum:
Sockets and Internet Protocols
Server / Client with Threads
feda alshahwan
Ranch Hand
Posts: 170
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am creating simple server /client with threads but I have a problem it is not executable Could you tell me how to solve it please?here is the code:
package threadedwebserver;
import java.io.*; import java.net.*; /** * * @author fa00064 */ public class ThreadedWebServer { // ServerSocket serverSocket; // Socket connection; /** * @param args the command line arguments */ public static void main(String[] args) { try { ServerSocket serverSocket=new ServerSocket(40000); System.out.println("My Server is waiting and listening to port 40000......"); while (true) { Socket connetion=serverSocket.accept(); System.out.println("My Server is connected to client through port: "+ serverSocket.getLocalPort()); SocketThread t=new SocketThread(connection); t.start(); } } catch (Exception e) { System.err.println(e); } // TODO code application logic here } class SocketThread extends Thread { Socket connection; SocketThread(Socket connection){ this.connection=connection; } @Override public void run() { try { System.out.println("started the thread"); ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream()); ObjectInputStream input = new ObjectInputStream(connection.getInputStream()); String message="Hello from Server"; byte[] messageBytes=message.getBytes(message); output.writeObject(messageBytes); System.out.println("Message in Byte: " + messageBytes); input.close(); output.close(); } catch (IOException ex) { System.out.println(ex); } } } }
Joe Ess
Bartender
Posts: 9626
16
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You need to
tell us the details
. What did you expect to happen? What actually happened?
Is this problem significantly different from the
one you've posted over here
?
[
How To Ask Questions On JavaRanch
]
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
simultaneosly running server class and JFrame, the JFrame wont show the components.
Send a file across the network
Reseting socket after few seconds
Help on Serializable
java.net.SocketException: Connection reset
More...