|
You might get a better response by posting your question in the WCF forum[^].
Use the best guess
|
|
|
|
|
Goodness! I didn't even notice there was a forum dedicated to WCF. Thanks for pointing out.
|
|
|
|
|
Hello,
I've just started to programm in C++, using Builder C++. I need to stablish comunication via internet between two computers. I've succed using the ClientSocket Component and the ClientServer but only if the computers are in a local network but not if the computers are in different networks. Here is my code for the server:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::BAbrirClick(TObject *Sender)
{
ServerSocket1->Port=StrToInt(Npuerto->Text);
ServerSocket1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::BCerrarClick(TObject *Sender)
{
ServerSocket1->Close();
BAbrir->Enabled=true;
BCerrar->Enabled=false;
BEstado->SimpleText="Servidor Cerrado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = false;
}
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
BEstado->SimpleText="Conectado desde "+Socket->RemoteAddress;
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
}
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections-1);
BEstado->SimpleText="Desconectado de "+Socket->RemoteAddress;
}
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
char * buffer;
int len;
AnsiString Mensaje;
int i;
int *tam;
tam = new int;
*tam = Socket->ReceiveLength();
len=Socket->ReceiveBuf(buffer,*tam);
buffer[len]=0;
TTime hora = TTime::CurrentTime();
AnsiString MensajeIn = Socket->RemoteAddress;
MensajeIn += " A las " + TimeToStr(hora) + " Dice" "----->";
ChatBox->Lines->Add(MensajeIn +StrPas(buffer));
BEstado->SimpleText=IntToStr(len)+"Nuevo mensaje entrante!";
Mensaje = StrPas(buffer);
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
delete[] buffer;
}
void __fastcall TForm1::BEnviarClick(TObject *Sender)
{
char buffer[256];
int i;
AnsiString Mensaje = CampoMensaje->Text;
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
TTime hora = TTime::CurrentTime();
ChatBox->Lines->Add("Servidor a las " +TimeToStr(hora)
+ " dice----->" + Mensaje);
}
void __fastcall TForm1::LimpiarClick(TObject *Sender)
{
ChatBox->Clear();
}
void __fastcall TForm1::CampoMensajeKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BEnviarClick(CampoMensaje);
}
void __fastcall TForm1::NpuertoKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BAbrirClick(Npuerto);
}
void __fastcall TForm1::TcpServer1Accept(TObject *Sender,
TCustomIpClient *ClientSocket)
{
TcpServer1->RemotePort = StrToInt(Npuerto->Text);
TcpServer1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::TcpServer1CreateHandle(TObject *Sender)
{
NOnline->Text=IntToStr(TcpServer1->Active-1);
BEstado->SimpleText="Desconectado de "+TcpServer1->LocalHostName();
}
How can I implement comunication (a simple chat is enough) between the two computers?
|
|
|
|
|
First of all, good job on starting out with C++. It can be a daunting task, but I've no doubt you'll rise to the challenge. I would like to point out, however, that this is the C# forum and not the C++[^] one. You'll have more luck getting an answer if you ask your question in the correct forum.
|
|
|
|
|
Oh my god, I'm so sorry, many hours without any break in front of the computer. Thanks for notify
|
|
|
|
|
We've all been there, there is even a phrase for it[^]
“Education is not the piling on of learning, information, data, facts, skills, or abilities - that's training or instruction - but is rather making visible what is hidden as a seed” “One of the greatest problems of our time is that many are schooled but few are educated”
Sir Thomas More (1478 – 1535)
|
|
|
|
|
Hello Experts,
I am working on an Excel application and I have input in the form of an HTML table string.I need to past this string in my excel work sheet.
Please let me know how can I do this?
Thanks,
Raesa
|
|
|
|
|
|
Hello Richard,
Thanks for the reply.
I had actually gone through the articles before, but could not find help.
I actually tried using the below code for pastiny HTML table string to excel datasheet, but it throws a pastespecial error and i'm not sure how to solve it.
-------
Excel.Application objExcelApp;
Excel.Workbook objWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
objExcelApp = new Excel.Application();
objWorkBook = objExcelApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)objWorkBook.Worksheets.get_Item(1);
PulleyResponse respUser = PulleyOutputList.ElementAt(0).Key;
Clipboard.SetData(DataFormats.Html, respUser.htmlStressTable);
objWorkBook.ActiveSheet.Range("A1").PasteSpecial(Excel.XlPasteType.xlPasteAll,Excel.XlPasteSpecialOperation.xlPasteSpecialOperationAdd,false, false);
objWorkBook.ActiveSheet.Range("A1").Value = objWorkBook.ActiveSheet.PasteSpecial(Clipboard.GetText());
string sDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (objWorkBook != null)
objWorkBook.SaveAs("c:\\Test.xls", misValue, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlNoChange, misValue, misValue, misValue, misValue, misValue);
objExcelApp.Quit();
ReleaseObject(objWorkBook);
ReleaseObject(objExcelApp);
------
I would glad if I could get some advice on this if I am doing something wrong.
Thanks,
Raesa
|
|
|
|
|
You need to look at the information in the exception to see why it's failing.
Use the best guess
|
|
|
|
|
Hello Richard,
I am getting a COMException - "
Unable to get the PasteSpecial property of the Range class " at this line
objWorkBook.ActiveSheet.Range("A1").Value = objWorkBook.ActiveSheet.PasteSpecial(Clipboard.GetText());
I am not sure what I must do.
Thanks
Raesa
|
|
|
|
|
Hello,
As an alternative, you can take a look at IPOI[^].
Cheers,
Eduardo
|
|
|
|
|
According to the documentation[^] PasteSpecial is a method of a Range object, not a WorkSheet .
Use the best guess
|
|
|
|
|
|
That link is for VBA, the link you need to use is this one[^]. Also, if you read the documentation it states "This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.". You need to use the Range object, as I mentioned previously.
Use the best guess
|
|
|
|
|
Hi Richard,
Thank you for the link.
I will have a look again at my implementation.
Thanks,
Raesa
|
|
|
|
|
...
[START]
blaaa blaa blaa
T h i s
(this is an empty line)
{END]
...
another line
--------------------------------------
I have been trying to remove empty lines appearing between
[START] and {END] within a word document.
Code seems to work if I did not have a textbox at top of my document. It seems that the textbox is also cleared once such operation takes place.
wordapp = new Word.Application();
wordapp.Visible = false;
doc = wordapp.Documents.Open(wordPath);
paragraphs = doc.Paragraphs;
bool flag = false;
foreach (Word.Paragraph paragraph in paragraphs)
{
string s = paragraph.Range.Text;
string y = paragraph.Range.Text.Trim();
if (paragraph.Range.Text == "<NE>\r")
{
flag = true;
paragraph.Range.Select();
wordapp.Selection.Delete();
continue;
}
else if (paragraph.Range.Text == "</NE>\r")
{
flag = false;
paragraph.Range.Select();
wordapp.Selection.Delete();
continue;
}
else if (paragraph.Range.Text.Trim() == string.Empty )
{
if (flag)
{
paragraph.Range.Select();
wordapp.Selection.Delete();
}
continue;
}
}
doc.Save();
wordapp.Quit();
is there any other way to achieve what I do using Range in Word or dealing with a textbox in Word?
Student of life
|
|
|
|
|
Hi Saeed,
Could you clarify exactly what you mean by "textbox at top of my document" ?
I note the variable 'y you define in your code is never used.
It appears to me your code deletes the tags "<NE>" and "</NE>," as well as white-space between them: is that correct ?
yours, Bill
string test = "\r";
string afterTest = test.Trim();
MessageBox.Show(string.IsNullOrEmpty(afterTest).ToString());
MessageBox.Show(string.IsNullOrWhiteSpace(afterTest).ToString());
MessageBox.Show((afterTest == string.Empty).ToString());
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
modified 17-May-13 8:52am.
|
|
|
|
|
Hi,
I have a Java program that signed a token using the private key and SHA1 algorithm. Now I try to verify it using the public key and SHA1. The verification fails. Is there any compatibility issue here or I am missing something? Thanks.
Best,
Jun
|
|
|
|
|
Oops wrong forum. Recommend you delete this thread and post your question in the right forum.
|
|
|
|
|
I am programming a bit counter, a method that returns a List < int > of the positions of the bits that are "on" in a UInt32. I was reviewing the code when I encountered
position--;
bit >>= 1;
To my mind these two statements need to be atomic. To achieve at least the notion of atomicity in C#, I would change the code to
position--; bit >>= 1;
I am fiercely against this in a statement body. But in this case I think it signals atomicity. Is there a better way to do this?
Gus Gustafson
|
|
|
|
|
This is coolest bitcount I've seen.
{
c = (c >> 1 & 0x55555555) + (c & 0x55555555);
c = (c >> 2 & 0x33333333) + (c & 0x33333333);
c = (c >> 4 & 0x0f0f0f0f) + (c & 0x0f0f0f0f);
c = (c >> 8 & 0x00ff00ff) + (c & 0x00ff00ff);
return (c >> 16) + (c & 0x0000ffff);
}
|
|
|
|
|
|
Nice. Thanks.
|
|
|
|
|
Is this an answer to my question?
Gus Gustafson
|
|
|
|