Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 04-12-2007, 06:52 PM Java Help
Junior Talker

Posts: 2
Name: Nick
Trades: 0
I've been working on this for about 2 days and I've not progressed at all.

I've made a Java Socket server. The server starts, it reports if someone connects BUT when it comes to sending data to the server it's all built up and can only be dealt with when they have disconnected from the server.

This is what's run when a client connects.
Code:
    public void run() 
    {
        input = "";
    
        try 
        {
            DataInputStream in = new DataInputStream(server.getInputStream());
            PrintStream out = new PrintStream(server.getOutputStream(), true);
            
            while((input = in.readLine()) != null)
            {
                System.out.println(input);
            }
            
            System.out.println("[" + new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date()) + "] - Connection closed - ID " + this.clientId);
            server.close();
        }
        catch (IOException ioe) 
        {
            System.out.println("IOException on socket listen: " + ioe);
            ioe.printStackTrace();
        }
    }
I do hope someone can help because I don't know of any Java forums to ask for help.
EGONick is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-13-2007, 02:57 AM Re: Java Help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Two that I know of are;

http://www.tek-tips.com/threadminder.cfm?pid=269
&
http://www.codingforums.com/forumdisplay.php?f=54
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-13-2007, 11:33 AM Re: Java Help
Junior Talker

Posts: 2
Name: Nick
Trades: 0
Thanks. I'll try those.
EGONick is offline
Reply With Quote
View Public Profile
 
Old 04-13-2007, 02:01 PM Re: Java Help
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
You don't have enough code for an analysis but, from your description, I'd say you probably need to flush you stream after sending data.
Also, try replacing:
Code:
DataInputStream in = new DataInputStream(server.getInputStream());
with
Code:
DataInputStream in = new DataInputStream(new BufferedInputStream(server.getInputStream()));
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Java Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13338 seconds with 12 queries