TcpClient Demo : TcpClient « Network « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » Network » TcpClient 
TcpClient Demo
 
#include "stdafx.h"
using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Threading;
using namespace System::Text;

void main()
{
    Socket^ server = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
    IPEndPoint^ iped = gcnew IPEndPoint(IPAddress::Parse("127.0.0.1")12345);
    server->Connect(iped);

    array<unsigned char>^ msg = gcnew array<unsigned char>(1024);
    int rcv = server->Receive(msg);

    Console::WriteLine(Encoding::ASCII->GetString(msg, 0, rcv));

    msg = Encoding::ASCII->GetBytes("input");
    server->Send(msg, msg->Length, SocketFlags::None);

    msg = gcnew array<unsigned char>(1024);
    rcv = server->Receive(msg);
    Console::WriteLine(Encoding::ASCII->GetString(msg, 0, rcv));
    server->Shutdown(SocketShutdown::Both);
    server->Close();
}

   
  
Related examples in the same category
1.TcpClient Stream
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.