UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Socket Program & Console (thread)?

#1 2004-05-25 02:29 AM

NightCrawler
Member
From: Baton Rouge, LA
Registered: 2003-04-10
Posts: 4
Website

Re: Socket Program & Console (thread)?

Hi everybody,

I'm working on developing a server for windows/unix that needs to be able to run console utilities for administration.  The problem that I am having is that every time one of the console utilities is started, the network stops processing sockets until that function has returned.  What is the most compatible technique to use in order for this program to function on both platforms (IE Console utilities do not block the "server" from operating)

Offline

#2 2004-05-25 01:29 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Socket Program & Console (thread)?

Use fork() and execl() instead of exec().

Offline

#3 2004-05-26 03:52 AM

NightCrawler
Member
From: Baton Rouge, LA
Registered: 2003-04-10
Posts: 4
Website

Re: Socket Program & Console (thread)?

Thanks for the fast response :).  I've noticed that fork() and execl() both work with externally compiled programs, since this is only needed for a class of functions (Account Manager (Main Function, calls all others)), is it possible to use some type of cross compatible thread where I can just pass the function in and it will be able to access the data area of the primary server thread?  (I've noted you can do something like this with _beginthread(), but that's windows and probably isn't compatible with UNIX.  Thanks for all your time.

Offline

#4 2004-05-26 04:47 AM

Nope
Administrator
From: Germany
Registered: 2004-01-24
Posts: 385
Website

Re: Socket Program & Console (thread)?

pthread_create is roughly the same I guess. It starts a new thread within
the program and has full access to the global variables. You can also pass
on pointers in a way. The pthread library is a posix one that should be(?)
available in Windows also, so using it might help keep your code portable
with less hassle.

There are several ways to build a console thingy. You could write a real
console and punch it into the main app by pipes. That would keep it
seperate and can be expanded via sockets to allow web based
administration. An external method could also be integrated into some
other application that might work as a admin tool for several parts of a
server.

Offline

#5 2004-05-26 11:10 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Socket Program & Console (thread)?

Because it was a console thing I assumed that the "utilities" were external little programs. Turns out that I read the rest of your post rather poorly too.

As Nope said, what you need are threads. There is a port to Windows of the pthread library, but it isn't standard. It's relatively very little work to make simple wrapper functions to wrap the thread create and mutex lock functions of pthread and Windows's critical section stuff.

Offline

  • Index
  • » C++
  • » Socket Program & Console (thread)?

Board footer

Powered by FluxBB