Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to split pcl data file to print separate page Pin
hunghn27-Jan-05 19:40
hunghn27-Jan-05 19:40 
Generalproblem in dns query Pin
Ankit Aneja27-Jan-05 19:08
Ankit Aneja27-Jan-05 19:08 
Questionhow to make word so that it doesnt create .tmp Pin
Jetli Jerry27-Jan-05 18:11
Jetli Jerry27-Jan-05 18:11 
AnswerRe: how to make word so that it doesnt create .tmp Pin
shaveyourhead27-Jan-05 18:27
shaveyourhead27-Jan-05 18:27 
GeneralRe: how to make word so that it doesnt create .tmp Pin
Jetli Jerry27-Jan-05 20:07
Jetli Jerry27-Jan-05 20:07 
AnswerRe: how to make word so that it doesnt create .tmp Pin
David Crow28-Jan-05 2:58
David Crow28-Jan-05 2:58 
GeneralMulti-user server Pin
Timothy Grabrian27-Jan-05 17:26
professionalTimothy Grabrian27-Jan-05 17:26 
GeneralRe: Multi-user server Pin
trelliot28-Jan-05 2:57
trelliot28-Jan-05 2:57 
Well if you don't like MFC, try this unix sample:

/*
* ClockServer.c
* sample Unix (SCO) clock server for pcsclock
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

/* network includes */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

/* PCS specific */
#include "token.h"
#include "unixser.h"

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

/* the default port */
int Port = 9999;

// The socket
int Socket;
// The connection the child talks through
int NewConnection;

int SerialPort, Opened;
char Buf[BUFSIZ];

enum tagCOMMANDS
{
UNKNOWN = -1,
wOPEN,
wCLOSE
};

KEYWORDS KeyWords[]=
{
"open", 4,
// PCSClock sends 'CLOSE' just before it does so
"CLOSE", 5,
NULL, 0
};

/*
* Trim a string of spaces (Control characters remain)
*/
char *Trim(char *String)
{
int sLen;

if(String != (char *)NULL)
{
sLen = 0;
while(*(String + sLen) == ' ')
sLen++;
if(sLen)
strcpy(String, String + sLen);

if((sLen = strlen(String)) > 0)
{
while(sLen && *(String + sLen - 1) == ' ')
{
*(String + sLen - 1) = 0;
sLen--;
}
}
}
return(String);
}

int InterpCommand(char *Buf)
{
char *cp = Buf;
char Token[128];

if(GetToken(&cp, Token) != FINISHED)
{
switch(IsReservedVar(Token, KeyWords))
{
case wOPEN:
if(!Opened)
{
fprintf(stderr, "Opening %s\n", cp);
SerialPort = ComOpen(Trim(cp), 256, 256);
if(SerialPort >= 0)
{
if(ComSetParams(SerialPort, 9600, NONE, 8, 1, NONE) == OK)
{
write(NewConnection, "OK", 2);
Opened = TRUE;
}
}
if(!Opened)
{
write(NewConnection, "Fail", 4);
perror("Open port failed");
}
}
break;

case wCLOSE:
if(Opened)
ComClose(SerialPort);
Opened = FALSE;
return(FALSE);

default:
fprintf(stderr, "unknown command %s\n", Buf);
break;
}
}
return(TRUE);
}

int main(int argc, char **argv)
{
struct sockaddr_in Sock_IN;

if(argc == 2)
{
int Tmp;
Tmp = atoi(argv[1]);
if(Tmp > 0)
Port = Tmp;
}

if((Socket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket() failed");
exit(1);
}

memset(&Sock_IN, 0, sizeof(Sock_IN));
Sock_IN.sin_family = AF_INET;
Sock_IN.sin_port = htons(Port);
Sock_IN.sin_addr.s_addr = htonl(INADDR_ANY);

if(bind(Socket, (struct sockaddr *)&Sock_IN, sizeof(Sock_IN)) == -1)
{
perror("bind() failed");
exit(1);
}

if(listen(Socket, 5) == -1)
{
perror("listen() failed");
exit(1);
}

while(TRUE)
{
int Pid;

fprintf(stderr, "Accepting");
if((NewConnection = accept(Socket, 0, 0)) == -1)
{
perror("accept() failed");
exit(1);
}

/* Start a new child */
if((Pid = fork()) == -1)
{
perror("fork() failed");
exit(1);
}

if(Pid == 0)
{
int FirstTime = TRUE;
Opened = FALSE;
SerialPort = -1;

Pid = getpid();
while(TRUE)
{
int Count;

*Buf = 0;
if((Count = read(NewConnection, Buf, sizeof(Buf))) == -1)
{
perror("read() failed");
exit(1);
}

if(!Count)
break;

Buf[Count] = 0;
fprintf(stderr, "%d Read: %s\n", Pid, Buf);

/* Clock commands always begin with '>' */
if(*Buf == '>')
{
if(Opened)
{
clock_t Tick;
char *cp;
char SerBuf[BUFSIZ];

if(write(SerialPort, Buf, Count) < 0)
perror("Write serial port failed");
// Don't know why but on this stupid SCO machine
// the io seems so slow that we now have to wait
// for serial output to complete
sleep(1);

cp = SerBuf;
*cp = 0;

Tick = clock();
while(clock() - Tick < 3000)
{
if(read(SerialPort, cp, 1) == 1)
{
cp++;
*cp = 0;

/* Clock replies always end in <CR> */
if(*(cp - 1) == '\r')
{
Count = strlen(SerBuf);
if(send(NewConnection, SerBuf, Count, 0) != Count)
perror("send failed");
fprintf(stderr, "%d Sending %s\n", Pid, SerBuf);
break;
}
Tick = clock();
}
}
}
else
perror("No open received");
}
else if(*Buf)
if(!InterpCommand(Buf))
break;
}
close(NewConnection);
fprintf(stderr, "%d child dying", Pid);
exit(0);
}
/* Close the parent's connection */
close(NewConnection);
}
}

Generalexporting global operator+ function from DLL Pin
Jim Crafton27-Jan-05 17:04
Jim Crafton27-Jan-05 17:04 
GeneralRe: exporting global operator+ function from DLL Pin
KaЯl27-Jan-05 21:28
KaЯl27-Jan-05 21:28 
GeneralRe: exporting global operator+ function from DLL Pin
Jim Crafton28-Jan-05 3:27
Jim Crafton28-Jan-05 3:27 
GeneralRe: exporting global operator+ function from DLL Pin
Bo Hunter28-Jan-05 11:30
Bo Hunter28-Jan-05 11:30 
GeneralRe: exporting global operator+ function from DLL Pin
Jim Crafton28-Jan-05 13:47
Jim Crafton28-Jan-05 13:47 
GeneralAdd Lib in an Ocx project Pin
rushing27-Jan-05 16:59
rushing27-Jan-05 16:59 
GeneralC++ 4.2 smilie errors...help! Pin
shaveyourhead27-Jan-05 16:47
shaveyourhead27-Jan-05 16:47 
GeneralRe: C++ 4.2 smilie errors...help! Pin
Jim Crafton27-Jan-05 17:15
Jim Crafton27-Jan-05 17:15 
GeneralRe: C++ 4.2 smilie errors...help! Pin
shaveyourhead27-Jan-05 18:10
shaveyourhead27-Jan-05 18:10 
GeneralRe: C++ 4.2 smilie errors...help! Pin
Jim Crafton28-Jan-05 3:17
Jim Crafton28-Jan-05 3:17 
GeneralRe: C++ 4.2 smilie errors...help! - Problem Resolved. Thanks Pin
shaveyourhead28-Jan-05 5:28
shaveyourhead28-Jan-05 5:28 
GeneralSimple Calculator (Someone PLEASE HELP ME!!!!!) Pin
Atptour27-Jan-05 16:13
Atptour27-Jan-05 16:13 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
Jim Crafton27-Jan-05 17:18
Jim Crafton27-Jan-05 17:18 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
DHAPPREP27-Jan-05 17:55
DHAPPREP27-Jan-05 17:55 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
David Crow28-Jan-05 3:12
David Crow28-Jan-05 3:12 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
V.27-Jan-05 23:28
professionalV.27-Jan-05 23:28 
GeneralRe: Simple Calculator (Someone PLEASE HELP ME!!!!!) Pin
David Crow28-Jan-05 3:03
David Crow28-Jan-05 3:03 

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.