🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1320

Socket http connection and Proxy server

#1320
From: Stefan Schwing
Date: Thu, 07 Mar 2002 09:04
75 lines
2885 bytes
Hi there,

I try to set up a connection via a socket with proxy. Unfortunately, I don't
succeed: Here's the coding, any ides are greatly appreciated.

import  java.io.*;
import  java.net.*;

public class SocketOpenerTest {


    public static void main (String argv[]) {
        String host = http://server.com;
        int port = 88;
        System.getProperties().put( "proxySet", "true" );
        System.getProperties().put( "proxyHost", "proxy.mycompany" );
        System.getProperties().put( "proxyPort", "8080" );



        int timeout = 5000;
        Socket s = SocketOpener.openSocket(host, port, timeout);
        if (s == null) {
            System.out.println("The socket could not be opened.");

            System.out.println("Could not connect to host - " + host + " -
on port " + port);
        } else System.out.println("Successfully Opened " + s);
    }
}

class SocketOpener
    implements Runnable
{
    private String host;

    private int port;

    private Socket socket;


    public SocketOpener (String aHost, int aPort) {
        socket = null;

        host = aHost;

        port = aPort;
    }


    public static Socket openSocket (String aHost, int aPort, int timeout) {
        SocketOpener opener = new SocketOpener(aHost, aPort);
        Thread t = new Thread(opener);
        t.start();

        try {
            t.join(timeout);
        } catch (InterruptedException exception) {
        }
        return opener.getSocket();
    }


    public void run () {
        try {
            socket = new Socket(host, port);
        } catch (IOException exception) {
        }
    }


    public Socket getSocket () {
        return socket;
    }
};
Technical Details
Message-ID: <a67afb$seq$1@news1.wdf.sap-ag.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!peer1-sjc1.usenetserver.com!usenetserver.com!hub1.nntpserver.com!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!blackbush.xlink.net!blackbush.de.kpnqwest.net!news.sap-ag.de!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,bcad75568cb78f1a,start
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-03-07 01:10:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!peer1-sjc1.usenetserver.com!usenetserver.com!hub1.nntpserver.com!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!blackbush.xlink.net!blackbush.de.kpnqwest.net!news.sap-ag.de!not-for-mail
From: "Stefan Schwing" <stefan.schwing@sap.com>
Newsgroups: borland.public.jbuilder.java.api
Subject: Socket http connection and Proxy server
Date: Thu, 7 Mar 2002 10:04:43 +0100
Organization: SAPMarkets
Lines: 82
Message-ID: <a67afb$seq$1@news1.wdf.sap-ag.de>
Reply-To: "Stefan Schwing" <stefan.schwing@sap.com>
NNTP-Posting-Host: 10.19.78.96
X-Trace: news1.wdf.sap-ag.de 1015491883 29146 10.19.78.96 (7 Mar 2002 09:04:43 GMT)
X-Complaints-To: newsmaster@sap-ag.de
NNTP-Posting-Date: 7 Mar 2002 09:04:43 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200