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
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Sockets and Internet Protocols
whats wrong in my server code ?
naved momin
Ranch Hand
Posts: 692
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
actually my client is receiving all the message from the server but client is not able to send any message to server
or i m wrong at some position in my code please correct me
my server code
public class NetworkingDemo implements Runnable { ServerSocket s1 = null; Socket s; PrintWriter pw; /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here NetworkingDemo nd = new NetworkingDemo(); Thread job = new Thread(nd); job.start(); } public void run() { try { s1 = new ServerSocket(5000); while(true) { s = s1.accept(); pw = new PrintWriter(s.getOutputStream()); BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); String ss = rd.readLine(); System.out.println("server : " + ss); pw.println(ss); // BufferedReader bb = new BufferedReader(new InputStreamReader(s.getInputStream())); // String msg = bb.readLine(); // System.out.println(msg); pw.close(); } } catch (IOException ex) { Logger.getLogger(NetworkingDemo.class.getName()).log(Level.SEVERE, null, ex); } finally{ } } public void call() { BufferedReader bb = null; try { bb = new BufferedReader(new InputStreamReader(s.getInputStream())); String msg = bb.readLine(); System.out.println("msg:" + msg); bb.close(); } catch (IOException ex) { Logger.getLogger(NetworkingDemo.class.getName()).log(Level.SEVERE, null, ex); } finally { try { bb.close(); } catch (IOException ex) { Logger.getLogger(NetworkingDemo.class.getName()).log(Level.SEVERE, null, ex); } } } }
my client code
public class SimpleClientDemo implements Runnable { /** * @param args the command line arguments */ Socket s; public static void main(String[] args) { // TODO code application logic here SimpleClientDemo s = new SimpleClientDemo(); Thread job = new Thread(s); job.start(); //catch(ConnectException e) } public void run() { while(true) try { s = new Socket("127.0.0.1", 5000); InputStreamReader st = new InputStreamReader(s.getInputStream()); BufferedReader bf = new BufferedReader(st); String str = bf.readLine(); System.out.println("server : " + str); // call(); bf.close(); } catch(IOException ex) { System.out.println("cant "); } } private void call() { PrintWriter pw = null; try { pw = new PrintWriter(s.getOutputStream(), true); BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); String ss = rd.readLine(); System.out.println("write msg (server):" + ss); pw.println(ss); } catch (IOException ex) { Logger.getLogger(SimpleClientDemo.class.getName()).log(Level.SEVERE, null, ex); } finally { pw.close(); } } }
The Only way to learn is ...........do!
Visit my blog
http://inaved-momin.blogspot.com/
Philip Thamaravelil
Ranch Hand
Posts: 99
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
NetworkingDemo implements runnable right?
So why not do:
Thread
job = new NetworkingDemo();
job.start();
That's where I would start.
Cheers,
Philip
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
socket not accepting data 2nd time
How to communicate between one server and multiple clients
why thread is in running or runnable state why it is not terminated ?
threads concurrency problem
How to Change the File Name for Each Uploaded Files to the Socket Server?
More...