网络-编程
问题描述:
请为我解释一下什么是TCP数据包协议?
如果我要使用它来使客户端服务器程序在两台计算机之间进行聊天(应用程序通过套接字连接)
Please explain for me, what is protocol of TCP packet ?
If I want to use that to make the client-server program for chat between 2 computers ( application connect with socket)
答
该协议被命名为TCP,即传输控制协议,详情请参见: http://en.wikipedia.org/wiki/Transmission_Control_Protocol [来自同一端口号的多个客户端 [如何将byte []发送到另一台PC [ ^ ],
在局域网上与两个Windows应用程序进行通信. [ ^ ].
使用v.2.0,您可以将它们全部用于经典远程处理(包括端到端).也就是说,WCF不可用,您将需要v.3.5或4.0.对于您的任务,最合适的方法可能是基于TcpListener/TcpClient
的方法.—SA
Protocol is named TCP, Transmission Control Protocol, see for more detail: http://en.wikipedia.org/wiki/Transmission_Control_Protocol[^].
It will work for your chat application. To get some ideas, look at my past answers.
This is a skeleton design of server with threads serving multiple remote sockets:
Multple clients from same port Number[^].
You can use TCP on several different levels, see:
how i can send byte[] to other pc[^],
Communication b/w two Windows applications on LAN.[^].
With v.2.0, you can use them all up to classical remoting, inclusively. That is, WCF is not available, you would need v.3.5 or 4.0. For your task probably the most suitable approach is the one based onTcpListener/TcpClient
.—SA
如果使用套接字编程,则不必担心TCP的基础工作.
有关TCP协议的概述,请在此处 [使用C#的TCP/IP聊天应用程序 [
You need not worry about the underlying working of TCP too much if you are using socket programming.
For an overview on the TCP protocol start here[^].
Afterwards, you can look at TCP/IP Chat Application Using C#[^] for an actual implementation of a chat program using TCP.
TCP是流协议.您将需要将流拆分为消息.对文本数据执行此操作的两种常见方法是插入特定字节作为定界符,或在每个消息前添加其长度.
您无需了解数据包级协议,TCP实施对您隐藏了这一点–从编程的角度来看,TCP连接是一个流(以及输入和输出流).
TCP is a stream protocol. You will need to split the stream up into messages. Two common ways to do that for textual data are to insert particular bytes as delimiters, or prepend each message with its length.
You do not need to know about the packet level protocol, TCP implementations hide that from you – from a programming point of view a TCP connection is a stream (well, an input and and output stream).