Ren-Huang‘s Blog | [C ]Visual C 的.NET Socket
来源:百度文库 编辑:神马文学网 时间:2024/06/12 18:24:59
Visual C++的.NET Socket
作者 icq 18:49 |靜態連結網址 |迴響 (0) |引用 (2) |點閱次數 (401) |Programming
怕忘記還是記一下吧。
// 這是使用應用程式精靈所產生之 VC++ 應用程式專案的主專案檔。
#include "stdafx.h"
#include
using namespace std;
#using
using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Collections;
int _tmain()
{
try
{
Socket *clientSocket;
Socket* serverSocket = new Socket(AddressFamily::InterNetwork,SocketType::Stream, ProtocolType::Tcp) ;
IPAddress *serverIP = IPAddress::Parse("140.113.131.47") ;//指定local ip
String* Port = "1234" ;//聆聽的port
IPEndPoint* serverhost = new IPEndPoint(serverIP, Int32::Parse(Port)) ;
serverSocket->Bind(serverhost) ;
serverSocket->Listen(50) ;
unsigned char recvbytes __gc[]=new unsigned char __gc[1024];
unsigned char sendbytes __gc[]=new unsigned char __gc[1024];
while (true)
{
clientSocket = serverSocket->Accept() ;
int len = clientSocket->Receive(recvbytes) ;//從client接收字串
char buffer[1024];
for(int i=0;ibuffer[i]=recvbytes[i];//轉換成char型態後,比較好處理
cout<<"Server收到:"<//收到php的回應後,想做什麼都可以,接著送出回應
char* reply="科科";
for(int i=0;isendbytes[i]=reply[i];
clientSocket->Send(sendbytes,strlen(reply),SocketFlags::None);//傳送資料就呼叫此函數,記得第二個參數是傳送的長度,一定要填對!
clientSocket->Close();//關閉socket
}
}
catch (Exception *ex)
{
Console::WriteLine(ex->ToString()) ;
}
return 0;
}
作者 icq 18:49 |靜態連結網址 |迴響 (0) |引用 (2) |點閱次數 (401) |Programming
怕忘記還是記一下吧。
// 這是使用應用程式精靈所產生之 VC++ 應用程式專案的主專案檔。
#include "stdafx.h"
#include
using namespace std;
#using
using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Collections;
int _tmain()
{
try
{
Socket *clientSocket;
Socket* serverSocket = new Socket(AddressFamily::InterNetwork,SocketType::Stream, ProtocolType::Tcp) ;
IPAddress *serverIP = IPAddress::Parse("140.113.131.47") ;//指定local ip
String* Port = "1234" ;//聆聽的port
IPEndPoint* serverhost = new IPEndPoint(serverIP, Int32::Parse(Port)) ;
serverSocket->Bind(serverhost) ;
serverSocket->Listen(50) ;
unsigned char recvbytes __gc[]=new unsigned char __gc[1024];
unsigned char sendbytes __gc[]=new unsigned char __gc[1024];
while (true)
{
clientSocket = serverSocket->Accept() ;
int len = clientSocket->Receive(recvbytes) ;//從client接收字串
char buffer[1024];
for(int i=0;i
cout<<"Server收到:"<
char* reply="科科";
for(int i=0;i
clientSocket->Send(sendbytes,strlen(reply),SocketFlags::None);//傳送資料就呼叫此函數,記得第二個參數是傳送的長度,一定要填對!
clientSocket->Close();//關閉socket
}
}
catch (Exception *ex)
{
Console::WriteLine(ex->ToString()) ;
}
return 0;
}
Ren-Huang‘s Blog | [C ]Visual C 的.NET Socket
Vincent's blog: Visual C 編譯器選項設置
C/S 多线程Socket类
Visual C .NET编程讲座之五
Visual C .NET编程讲座之六
Visual C .NET编程讲座之七
Visual C .NET编程讲座之八
防止对 Visual Basic .NET 或 C
Visual C .NET编程讲座之五
Visual C .NET编程讲座之(七)
在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分-.NET教程,C#语言
C++内置类型指针间的转换(原创) - Visual C++/vc.net - 开发工具和...
Visual C .NET编程讲座之二(1)
Visual C .NET编程讲座之二(3)
Visual C .NET编程讲座之二(4)
Visual C .NET编程讲座之三(2)
Visual C .NET编程讲座之三(3)
Visual C .NET编程讲座之四(1)
Visual C .NET编程讲座之四(2)
Visual C .NET编程讲座之四(3)
Visual C .NET编程讲座之四(4)
Visual C .NET编程讲座之四(5)
Visual C .NET编程讲座之四(6)
Visual C .NET编程讲座之二(3)