473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Problem with identifiers

Hi,

I took this socket listener from the VC++.NET help file. I inserted it
in my project.

What library do I have to include to have those identifier working:
string,
int32,
Byte,
server,
TcpListener,
Console

I'm including those library:
#include <stdlib.h>
#include <string>
#include <winsock2.h>
using namespace std;

but it don't seem to resolve the problem.

My c++ is rusty, but I'll get over it, I just need a little help to pass
through that.

Thank you very much.

Marty

void main() {
try {
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress* localAddr = IPAddress::Parse(S"127.0.0.1");

// TcpListener* server = new TcpListener(port);
TcpListener* server = new TcpListener(localAddr, port);

// Start listening for client requests.
server->Start();

// Buffer for reading data
Byte bytes[] = new Byte[256];
String* data = 0;

// Enter the listening loop.
while (true) {
Console::Write(S"Waiting for a connection... ");

// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient* client = server->AcceptTcpClient();
Console::WriteLine(S"Connected!");

data = 0;

// Get a stream Object* for reading and writing
NetworkStream* stream = client->GetStream();

Int32 i;

// Loop to receive all the data sent by the client.
while (i = stream->Read(bytes, 0, bytes->Length)) {
// Translate data bytes to a ASCII String*.
data = Text::Encoding::ASCII->GetString(bytes, 0, i);
Console::WriteLine(String::Format(S"Received: {0}",
data));
// Process the data sent by the client.
data = data->ToUpper();

Byte msg[] = Text::Encoding::ASCII->GetBytes(data);

// Send back a response.
stream->Write(msg, 0, msg->Length);
Console::WriteLine(String::Format(S"Sent: {0}", data));

}

// Shutdown and end connection
client->Close();
}
} catch (SocketException* e) {
Console::WriteLine(S"SocketException: {0}", e);
}

Console::WriteLine(S"\nHit enter to continue...");
Console::Read();
}
Nov 17 '05 #1
1 1025

Marty wrote:
Hi,

I took this socket listener from the VC++.NET help file. I inserted it in my project.

What library do I have to include to have those identifier working:
string,
int32,
Byte,
server,
TcpListener,
Console

I'm including those library:
#include <stdlib.h>
#include <string>
#include <winsock2.h>
using namespace std;

but it don't seem to resolve the problem.

My c++ is rusty, but I'll get over it, I just need a little help to pass through that.


This code is using .NET classes, therefore you need to use managed
extensions to use it (compile with /clr).

When using managed classes, you don't use #include files, rather you
#use assemblies, then add using namespace statements :
#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Net::Sockets;

you could replace the #using <assembly> statements with /AI compiler
flags.

Arnaud
MVP - VC

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Doug Fort | last post by:
This is an excerpt from a much longer post on the python-dev mailing list. I'm responding here, to avoid cluttering up python-dev. <snip> >Some English readers might not really imagine, but it...
3
by: skumar | last post by:
I am a newbie with C++ and unable to understand this warning/error message : localhost > g++ -Wall j++.cpp In file included from /usr/include/c++/3.2.2/backward/iostream.h:31, from j++.cpp:2:...
0
by: Leszek Dubiel | last post by:
----------------------------------------- BACKGROUND In my company (www.glass.biz) we use ERP software to compute what has to be done to do products for our customers. Main algorithm takes data...
2
by: Andrea Gelsogroove | last post by:
Hi guys this is my problem : I have created a js function where I can add fields on the fly, but there seems to be a small flaw with Mozilla. If you try to click on "Add" button you can see...
4
by: Erwin Gabler | last post by:
Trying to validate a document with a reference to a DTD ("PUBLIC" identifier): <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE systems-description PUBLIC "-//foo/nono" ""> .... The DTD uses...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
14
by: Army1987 | last post by:
#include <string.h> #include <stdlib.h> #include <stdio.h> char *_(char *str1, char *str2) { char *res; res = malloc((strlen(str1)+strlen(str2))*sizeof(char)); strcpy(res, str1);...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
3
by: Antonio Rivas | last post by:
Hello all. I've got a problem of multiple definition in a program that at first glance looks correct (I won't type the whole code, just the relevant one and as examples since seems is a linkage...
2
by: nd.sundar | last post by:
Hi, I have a collection of C source files (.c and .h). I need to find all identifiers which are used in that collection but not defined within the collection. The identifiers include pre-processor...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.