Advertisement Jump to content


This topic is now archived and is closed to further replies.


[java] Sockets and Threads

This topic is 6153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a program that connects to a socket, and watches for updates from the socket's inputstream... My problem is that the thread only seems to run twice. here's the code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class SocketTest extends javax.swing.JFrame implements Runnable{
    Socket s;
    InputStream is;
    BufferedInputStream bis;
    DataInputStream dis;
    OutputStream os;
    BufferedOutputStream bos;
    DataOutputStream dos;
    /** Creates new form SockTest */

    public SocketTest() {
        } catch (Exception e){
    public void connect() throws Exception {
        s = new Socket("",110);
        is = s.getInputStream();
        bis = new BufferedInputStream(is);
        dis = new DataInputStream(bis);
        os = s.getOutputStream();
        bos = new BufferedOutputStream(os);
        dos = new DataOutputStream(bos);
    // lots of other init stuff was here... bla bla bla.... 

     * @param args the command line arguments
    public static void main(String args[]) {
        SocketTest st =  new SocketTest();;
    Thread t = new Thread(this,"threadt");
    public void run() {
                console.append("\n" + dis.readLine());
            }catch(Exception e){e.printStackTrace();}
    private javax.swing.JTextArea console;
Any ideas? Edited by - idej-avaj on March 21, 2002 12:53:42 PM

Share this post

Link to post
Share on other sites
The reason that the Thread only seems to run twice is because only two lines of data will be sent. It seems you are using SMTP to connect to a POP3 server (not sure how this will work), but via SMTP, you will only get these two lines. More data will be sent, but only when you send data through the OutputStreams. Unfortunately, I don''t know SMTP well enough to help you, but:


should help you.

It''''s over for now... until yesterday begins again... tomorrow... tomorrow... tomorrow...

[Powerman 5000 - Watch the Sky for Me]

Share this post

Link to post
Share on other sites
Funny, I am currently working on the same sort of thing. Using sockets to connect to a webserver to pull data from a page. I found an awesome tutorial on the subject with full source code. I haven''t followed the other URL posted to see what it is about, but I highly recommend looking at this one:

good luck.

-Just when you think things are starting to look up, life grabs you by the jaws makes you open up wide and sh*ts down your throat.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!