语言tcp点对点源码(tcp对接)
本文目录一览:
VB实现TCP点对点通信(使用winsock控件)
在工程部件里添加个 Microsoft Winsock Control 6.0
From1:
Private Sub Command1_Click()
Winsock1.SendData Text3.Text
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Winsock1.LocalPort = 10001
Text1.Text = Winsock1.LocalIP
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Mystr As String
Winsock1.GetData Mystr
Text2.Text = Text2.Text Chr(13) Chr(10) Mystr
End Sub
Form2:
Private Sub Command1_Click()
Winsock1.RemoteHost = Text2.Text
Winsock1.Connect
End Sub
Private Sub Command2_Click()
Winsock1.SendData Text4.Text
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Winsock1.RemotePort = 10001
Text1.Text = Winsock1.LocalIP
End Sub
Private Sub Winsock1_Connect()
MsgBox ""
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim Mystr As String
Winsock1.GetData Mystr
Text3.Text = Text3.Text Chr(13) Chr(10) Mystr
End Sub
求TCP/IP 源代码 要求有中文注释~~~~~
lz说的应该不是协议,而是实现TCP/IP协议内容的具体代码,如C语言等;《用TCP/IP进行网际互联第二卷:设计、实现与内核》(第三版)【Internetworking
With
TCP/IP
Vol
II:Designed,Implementation,and
Internals
Third
Edition】上有C代码实现,但没有中文注释,只有英文注释,我想应该没有中文注释教材的吧,有也不好找的,反正我没见过,呵呵!
求一个C语言的TCP 客户/服务 连接示例代码
#include stdio.h
#include winsock2.h
#pragma comment(lib, "ws2_32.lib")
void main() {
// 初始化
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), wsaData );
if ( iResult != NO_ERROR )
printf("Error at WSAStartup()\n");
// 建立socket
SOCKET server;
server = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( server == INVALID_SOCKET ) {
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return;
}
// 绑定socket
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr( "127.0.0.1" );
service.sin_port = htons( 27015 );
if ( bind( server, (SOCKADDR*) service, sizeof(service) ) == SOCKET_ERROR ) {
printf( "bind() failed.\n" );
closesocket(server);
return;
}
// 监听 socket
if ( listen( server, 1 ) == SOCKET_ERROR )
printf( "Error listening on socket.\n");
// 接受连接
SOCKET AcceptSocket;
printf( "Waiting for a client to connect...\n" );
while (1) {
AcceptSocket = SOCKET_ERROR;
while ( AcceptSocket == SOCKET_ERROR ) {
AcceptSocket = accept( server, NULL, NULL );
}
printf( "Client Connected.\n");
server = AcceptSocket;
break;
}
// 发送接受数据
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Server: Sending Data.";
char recvbuf[32] = "";
bytesRecv = recv( server, recvbuf, 32, 0 );
printf( "Bytes Recv: %ld\n", bytesRecv );
bytesSent = send( server, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );
return;
}
SERVER语言tcp点对点源码的
tcp 点对点 通信
不行,必须是一端客户一端服务。tcp是面向连接的协议,与udp不一样。