|
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "helper.h"
#include <stdlib.h>
#include <stdio.h>
#define ECHO_PORT (2002)
#define MAX_LINE (1000)
int main(int argc, char *argv[]) {
int list_s;
int conn_s;
short int port;
struct sockaddr_in servaddr;
char buffer[MAX_LINE];
char *endptr;
if ( argc == 2 ) {
port = strtol(argv[1], &endptr, 0);
if ( *endptr ) {
fprintf(stderr, "ECHOSERV: Invalid port number.\n");
exit(EXIT_FAILURE);
}
}
else if ( argc < 2 ) {
port = ECHO_PORT;
}
else {
fprintf(stderr, "ECHOSERV: Invalid arguments.\n");
exit(EXIT_FAILURE);
}
if ( (list_s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(port);
if ( bind(list_s, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling bind()\n");
exit(EXIT_FAILURE);
}
if ( listen(list_s, LISTENQ) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling listen()\n");
exit(EXIT_FAILURE);
}
while ( 1 ) {
if ( (conn_s = accept(list_s, NULL, NULL) ) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling accept()\n");
exit(EXIT_FAILURE);
}
Readline(conn_s, buffer, MAX_LINE-1);
Writeline(conn_s, buffer, strlen(buffer));
if ( close(conn_s) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling close()\n");
exit(EXIT_FAILURE);
}
}
}
this is the code. there is one more file called "helper.h". this file contaisn cote for the readline and write functions. nothing important.
|
|
|
|
|
Mridang Agarwal wrote: #include <sys socket.h=""> /* socket definitions */#include <sys types.h=""> /* socket types */#include <arpa inet.h="">
Hey this is for UNIX!!
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
BTW, why did you say SOCKETS.h????? .. You really wasted many's time. When you ask something please see to that you are asking with the correct details.If you had mentioned the right word, we could have helped you faster. Good Luck nextime.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
i am really sorry guys. A messed up and all because of a small tpyo. Won't happen again. Thanks for all the help.
|
|
|
|
|
It's ok dude.. No problem
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Did you find this file?
|
|
|
|
|
I am using this code to save data in txt file but i just dont understand what went wrong in that it saves all data rather then that market detail only.
<br />
<br />
CString csMarket="EURUSD";<br />
CString usMarket ="USDJPY";<br />
CString gbMarket="GBPUSD" ;<br />
<br />
if(csMarket == Market)
{<br />
myfile.Open("EurUsd.txt",CFile.modeCreate | CFile.modeWrite);<br />
<br />
LPSTR buf;<br />
int i= m_MainEdit.GetLength();<br />
buf = m_MainEdit.GetBuffer(i);<br />
myfile.Write(buf,i);<br />
myfile.Close();<br />
<br />
}<br />
else if(strcmp( Market,"USDJPY") == 0) <br />
<br />
{<br />
myfile.Open("UsdJpy.txt",CFile.modeCreate | CFile.modeWrite);<br />
LPSTR buf1;<br />
int i = m_MainEdit.GetLength();<br />
buf1 = m_MainEdit.GetBuffer(i);<br />
myfile.Write(buf1,i);<br />
myfile.Close();<br />
}<br />
<br />
else if(gbMarket == Market)<br />
{<br />
myfile.Open("GbpUsd.txt",CFile.modeCreate | CFile.modeWrite);<br />
<br />
LPSTR buf2;<br />
int i = m_MainEdit.GetLength();<br />
buf2 = m_MainEdit.GetBuffer(i);<br />
myfile.Write(buf2,i);<br />
myfile.Close();<br />
<br />
}<br />
|
|
|
|
|
Show the definition of Market . Wont thing's be more easier if you store your Market in a CString csMarket ?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
Market is the name of market like2 "usdjpy","gld","slv" etc and with this, rate of market and the days highest "bid" and the lowest "bid"
|
|
|
|
|
Try this,
<br />
CString Market;<br />
<br />
if(Market==usMarket)<br />
{<br />
}<br />
else if(Market==csMarket)<br />
{<br />
<br />
}<br />
else if(Market==gbMarket)<br />
{<br />
<br />
}<br />
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
I cant do thsi caz Market detail are coming from remote server i need to save only this 3 market detail in txt file
CString csMarket="EURUSD";
CString usMarket ="USDJPY";
CString gbMarket="GBPUSD" ;
|
|
|
|
|
You'll get any one of these at a time ? if so, you can do one thing :
From your code, Market looks like a char* so you would better do,
<br />
myfile.Open(Market,CFile.modeCreate | CFile.modeWrite);<br />
So that it writes into separate files according to the value of "Market".
Or I still dont get your problem?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
abrakadbra wrote: if(csMarket == Market) //,myfile.Open("EurUsd.txt",CFile.modeCreate | CFile.modeWrite)
{
myfile.Open("EurUsd.txt",CFile.modeCreate | CFile.modeWrite);
// myfile.Write((LPCTSTR)m_MainEdit,m_MainEdit.GetLength()*sizeof(TCHAR));
LPSTR buf;
int i= m_MainEdit.GetLength();
buf = m_MainEdit.GetBuffer(i);
myfile.Write(buf,i);
myfile.Close();
}
Is this the snippet of code that you are questioning?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
yes do you have any idea how to correct the following code....how to store only one market data in one txt file.
|
|
|
|
|
abrakadbra wrote: yes do you have any idea how to correct the following code....how to store only one market data in one txt file.
Like has been said at least two times before, change buf to only contain the data you wanted saved to the file.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is there any source code or link for databse programming which tell us how to save data in datbase coming from remote server.
|
|
|
|
|
|
abrakadbra wrote: Is there any source code or link for databse programming which tell us how to save data in datbase coming from remote server.
try msdn samples! or google
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
Exception Handeling seems to hide behind obsure procedures. I've read and understood the principles as set out in Matt Pietrecks various articles on the subject, somehow, VCPP5.00 appears to work differently.
All I want to do is throw an exception, as a DWORD value of my liking, so that a catch block can either deal with it true a switch statement, or throw it further down the chain by default. It occurs to me that that's sort of basic, which even VCPP5.00 should be able to handle.
LateNightsInNewry
|
|
|
|
|
You're using VC5 ? Why ?
However, I'd have hoped it could do that, although C++ exceptions kind of suck if you're in any way used to .NET ones.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Why and How would that upset .NET?? My code is not NET aware, and will not ever be required to run under NET
LateNightsInNewry
|
|
|
|
|
Imagine if your company car was a Ferrari and on weekends you had to drive a scooter. The scooter is still a scooter, but you'd feel a lot worse about sitting on it if you were used to a Ferrari.
It won't matter to .NET, I meant that if you had used .NET exceptions and then tried to use C++ exceptions, you'll find yourself wishing they did more.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Get your Drift, however;
This question is not so much about a Ferari which I do not posess, but about the scooter going from A to B. You may be fortunate enough to write for a client base equiped with the latest harware. I am not so fortunate, the Software I write is supposed to run on Win98-SE. The question is still the same, Hoe do I throw exceptions by say Number under VCPP5.0
LateNightsInNewry
|
|
|
|
|
LateNightsInNewry wrote: the Software I write is supposed to run on Win98-SE
OK. Are you under the mistaken impression that this means you need to use VC5 ?
Either way, I can't comment on VC5, but I would expect in general that anything that VC6 does in this regard, VC5 should be fine. Perhaps if you posted your code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: Perhaps if you posted your code ?
The problem with that is, The code has not been written yet. I am doing something before I write code, which is called 'Planning your Process'. The Larger plan is as follows:-
I am writing a Server Client Program, where the Server maintains a Database, which is accessed by clients by requests for either information or update. Server and Clients typically run on different machines on a local network, but communicate by structured messages sent over a WIN32 Pipe. I am now investigating the possibility of terminating a long process on the Server, by means of the User on the Client Terminal clicking on 'Cancel' on the Wait box.
The entire design of the system is 'Proprietory' and 'From the Ground up', and is purpously designed to be non-compatible with any Microsoft Database format. Iam now looking for an exception handeling mechanism which handles exceptions by GUID_EXCEPTION_ID. If something like this exists already, I'll use it. If it does Not exist I've to Invent it.
LateNightsInNewry
|
|
|
|