Article View: borland.public.cppbuilder.internet.socket
Article #3934using TIdTCPServer
From: Simon Guertin
Date: Thu, 05 May 2005 14:15
Date: Thu, 05 May 2005 14:15
70 lines
3017 bytes
3017 bytes
Hi, I am a long time Java user, so I think in Java a little bit. I need
to create a TCP server and I would like to know if using the
TIdTCPServer will be good for me or if I should implement a server that
looks like this (at the bottom of the email):
my question is, : I need to know where to put all my processing of the
connection.. other than in the TCPServerExecute() method of the
IndyServer. Should I re-write my own server..can I change the way the
threads are started?
my application will be a server that accepts connection to register and
activate a software online.. with a little bit of UI.
thank you
Simon
java server->
the server:
public class KKMultiServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.err.println("Could not listen on port: 4444.");
System.exit(-1);
}
while (listening)
new KKMultiServerThread(serverSocket.accept()).start();
serverSocket.close();
}
}
thread that process the connection:
public class KKMultiServerThread extends Thread {
private Socket socket = null;
public KKMultiServerThread(Socket socket) {
super("KKMultiServerThread");
this.socket = socket;
}
public void run() {
try {
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket
.getInputStream()));
String inputLine, outputLine;
KnockKnockProtocol kkp = new KnockKnockProtocol();
outputLine = kkp.processInput(null);
out.println(outputLine);
while ((inputLine = in.readLine()) != null) {
outputLine = kkp.processInput(inputLine);
out.println(outputLine);
if (outputLine.equals("Bye"))
break;
}
out.close();
in.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Technical Details
Message-ID:
<427a2a63$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.usenet.com!news.moat.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,2b2bb416a158f43e,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 05 May 2005 10:15:08 -0400 From: Simon Guertin <sguertin_AT@trellianetworks.com> User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: using TIdTCPServer Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.71.74.98 Message-ID: <427a2a63$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1115302499 67.71.74.98 (5 May 2005 07:14:59 -0700) Lines: 73 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.usenet.com!news.moat.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail