Click here to Skip to main content
15,908,906 members
Home / Discussions / C#
   

C#

 
GeneralRe: System.Data.SqlClient.SqlException Pin
Igor Sukhov16-Nov-05 3:10
Igor Sukhov16-Nov-05 3:10 
GeneralRe: System.Data.SqlClient.SqlException Pin
Lebanese16-Nov-05 20:24
Lebanese16-Nov-05 20:24 
QuestionCrystal Report deployment problem Pin
memoboy15-Nov-05 22:05
memoboy15-Nov-05 22:05 
QuestionRe: i traid to merg Pin
memoboy16-Nov-05 1:15
memoboy16-Nov-05 1:15 
QuestionAbout Progressbar Pin
Sina_Ad15-Nov-05 21:37
Sina_Ad15-Nov-05 21:37 
QuestionWhat does Accesible Role do? Pin
Sina_Ad15-Nov-05 21:29
Sina_Ad15-Nov-05 21:29 
Questionwindows service Pin
Ankit Aneja15-Nov-05 19:37
Ankit Aneja15-Nov-05 19:37 
AnswerRe: windows service Pin
Sean Michael Murphy16-Nov-05 4:57
Sean Michael Murphy16-Nov-05 4:57 
Ankit Aneja wrote:
if yes where will i write my socket server code
will it be in OnStart


You don't give enough information about your problem to know if sockets will solve it, but if you do end up writing a TCP server in your service, you can't put the listening code in OnStart.

The simplest way to do this is with a blocking listener socket, and if you put it in OnStart, your service will never completely start. Put the listener on a different thread, and spark up the thread in the OnStart event. OnStart completes, and your service is off to the races.

This isn't scalable but works well for, say, proxying requests for remote resources by a single application.

C#
// Declarations
private static TcpListener _listener         = null;
private static Thread      _listenerThread   = null;
...
protected override void OnStart(string[] args) {
   _listenerThread = new Thread(new ThreadStart(MessageQueue));
   _listenerThread.Start();
}
...
private static void MessageQueue() {
   _listener = new TcpListener(System.Net.IPAddress.Any, 4242);
   _listener.Start();  // Blocks here until a connection on 4242 is made.
 
   while (true) {
      TcpClient      client = _listener.AcceptTcpClient();
      NetworkStream  stream = client.GetStream();
      // Read your message and write your reply
      // with the Stream...

Dig?

Share and enjoy.
Sean
GeneralRe: windows service Pin
Ankit Aneja17-Nov-05 18:44
Ankit Aneja17-Nov-05 18:44 
QuestionFile wrapper Pin
picasso215-Nov-05 19:17
picasso215-Nov-05 19:17 
QuestionHow i get C# ASP.net Source code for Study Pin
Suryakant S. Bharne15-Nov-05 19:02
professionalSuryakant S. Bharne15-Nov-05 19:02 
AnswerRe: How i get C# ASP.net Source code for Study Pin
Michael P Butler15-Nov-05 21:10
Michael P Butler15-Nov-05 21:10 
QuestionFTP Download - please help Pin
SheenSylesh15-Nov-05 17:58
SheenSylesh15-Nov-05 17:58 
AnswerRe: FTP Download - please help Pin
mwallon15-Nov-05 23:00
mwallon15-Nov-05 23:00 
Questioncalendar help~~ Pin
momoo15-Nov-05 13:43
momoo15-Nov-05 13:43 
AnswerRe: calendar help~~ Pin
Christian Graus15-Nov-05 14:18
protectorChristian Graus15-Nov-05 14:18 
GeneralRe: calendar help~~ Pin
momoo17-Nov-05 16:04
momoo17-Nov-05 16:04 
QuestionFind button with DataView and wildcard support? Pin
mscis15-Nov-05 13:19
mscis15-Nov-05 13:19 
Questionflash in a pocket pc project Pin
mwallon15-Nov-05 13:02
mwallon15-Nov-05 13:02 
AnswerRe: flash in a pocket pc project Pin
Joshua Quick15-Nov-05 15:36
Joshua Quick15-Nov-05 15:36 
GeneralRe: flash in a pocket pc project Pin
mwallon15-Nov-05 22:35
mwallon15-Nov-05 22:35 
GeneralRe: flash in a pocket pc project Pin
Joshua Quick16-Nov-05 7:32
Joshua Quick16-Nov-05 7:32 
GeneralRe: flash in a pocket pc project Pin
mwallon16-Nov-05 7:44
mwallon16-Nov-05 7:44 
QuestionAccess SQL Server Via Internet Pin
webhay15-Nov-05 11:36
webhay15-Nov-05 11:36 
AnswerRe: Access SQL Server Via Internet Pin
Judah Gabriel Himango15-Nov-05 12:00
sponsorJudah Gabriel Himango15-Nov-05 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.