Menu

c++ tcp

2008-10-18
2012-09-26
  • zaryk kiarans

    zaryk kiarans - 2008-10-18

    i am trying to take a c# chat program tutorial and convert it to c++. But I havent had too much luck finding out actually begin the process.

    [code]
    // Taken from http://www.devx.com/dotnet/Article/28083

    Imports System.Net.Sockets
    Imports System.Text

    Const portNo = 500
    Dim tcpclient As New TcpClient
    tcpclient.Connect("127.0.0.1", portNo)

    Dim ns As NetworkStream = tcpclient.GetStream
    Dim data As Byte() = Encoding.ASCII.GetBytes("Hello")

    '---send the text---
    ns.Write(data, 0, data.Length)

    [/code]

    So, I began by using

    [code]

    [C++]

    //take from http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.connect(VS.71).aspx for c++

    TcpClient* tcpClient = new TcpClient();
    tcpClient->Connect("127.0.0.1", 500);

    [/code]

    and it returns

    165 C:\Documents and Settings\semaj\My Documents\Projects\UnkIM\UnkIM.cpp `TcpClient' undeclared (first use this function)

    165 C:\Documents and Settings\semaj\My Documents\Projects\UnkIM\UnkIM.cpp `tcpClient' undeclared (first use this function)

    165 C:\Documents and Settings\semaj\My Documents\Projects\UnkIM\UnkIM.cpp `TcpClient' has not been declared

    //-----------------------------------

    I am not sure what i am to include or if it is even possible to use this in devc++. any ideas? Thanks.

     

    Related

    Code: code

    • cpns

      cpns - 2008-10-18

      The problem with VB.NET or even C# code is that it requires th .NET framework and Common Language Runtime(CLR). Dev-C++ (or specifically GCC) supports neither.

      Microsoft's C++ compiler supports C++/CLI a C++ superset that the supports constructs necessary to allow C++ to work as a .NET language. The path of least resistance here is to use Microsoft's free tools and C++/CLI. Or of course since Visual Basic 2008 Express is one of those free tools you could just use the code as is. .NET language interoperability is a feature of the .NET/CLR framework.

      Microsoft Visual Studio Express Editions can be found here: http://www.microsoft.com/express/product/default.aspx

      If you still want plain C++, and wish to use Dev-C++, you will have to use the lower level WinSock API directly. http://msdn.microsoft.com/en-us/library/ms740673(VS.85).aspx

      Note that if you continue to use Dev-C++, do not put your projcts in "C:\Documents and Settings\semaj\My Documents\". In some circumstances, the toolchain fails with paths containing spaces. Also when posting logs, use the raw text from the "Compile Log" tab, not the filtered text from the "Compiler" tab. Bothe these points are mad in the "PLEASE READ BEFORE POSTING A QUESTION" thread.

      Clifford

       
    • zaryk kiarans

      zaryk kiarans - 2008-10-18

      actually, my mistake, i believe its vb....it just said ".net" so I assumed it was C#.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.