第一范文网 - 专业文章范例文档资料分享平台

上海大学 计算机网络 实验报告

来源:用户分享 时间:2025/9/13 2:41:31 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

页眉 private string _username; private string _password; private bool _needPasswordl; private bool _passwordWrong; public TcpServerForm()

private void TcpReceiveForm_Load(object sender, EventArgs e) private void btnListen_Click(object sender, EventArgs e) private void btnDisconnect_Click(object sender, EventArgs e) void AcceptedConnection(IAsyncResult iar) void ReceivedData(IAsyncResult iar) void SentData(IAsyncResult iar) void ProcessDisconnection()

private void txtUserName_TextChanged(object sender, EventArgs e) private void txtPassword_TextChanged(object sender, EventArgs e) private void lblUserName_Click(object sender, EventArgs e) private void gnConnectInfo_Enter(object sender, EventArgs e)

private void lbMessage_SelectedIndexChanged(object sender, EventArgs e) private void lbNativeIP_SelectedIndexChanged(object sender, EventArgs e) private void lbConnectLog_SelectedIndexChanged(object sender, EventArgs e) }

TCP客户端:

public partial class TcpClientForm : Form {

Socket _client;

byte[] _receivedData = new byte[1024]; public TcpClientForm()

private void btnConnect_Click(object sender, EventArgs e)

5 / 22

页眉 private void btnDisconnect_Click(object sender, EventArgs e) private void btnSend_Click(object sender, EventArgs e) void Connected(IAsyncResult iar) void ReceivedData(IAsyncResult iar) void SentData(IAsyncResult iar) void ProcessDisconnection()

private void txtIP_TextChanged(object sender, EventArgs e) }

UDP接收端:

public partial class UdpReceiveForm : Form {

private bool ReadFlag = true; private Thread th;

private IPEndPoint remote; private UdpClient server; private int count = 0; private double num; public UdpReceiveForm() private void read()

private void btnReceive_Click(object sender, EventArgs e)

private void UdpReceiveForm_FormClosing(object sender, FormClosingEventArgs e) }

UDP发送端:

public partial class UdpSendForm : Form {

6 / 22

页眉 public UdpSendForm()

private void btnSend_Click(object sender, EventArgs e) private void txtIP_TextChanged(object sender, EventArgs e) private void lblInfo_Click(object sender, EventArgs e) }

主要算法描述;

异步调用与回调(部分): TCP服务端:

_server.BeginAccept(new AsyncCallback(AcceptedConnection), _server);//异步调用,开始接收连接 -> void AcceptedConnection(IAsyncResult iar) _client.BeginSend(sendMessage,

0,

sendMessage.Length,

SocketFlags.None,

new

AsyncCallback(SentData), _client);//异步调用,消息发送完毕执行->void SentData(IAsyncResult iar)

_client.BeginReceive(_receiveData, 0, _receiveData.Length, SocketFlags.None, new AsyncCallback(ReceivedData), _client);//密码正确,开始接收消息->void ReceivedData(IAsyncResult iar)

用户使用手册;

TCP客户端、TCP服务端:

1、用户打开TCP客户端并且输入服务端IP、用户名与密码(密码事先在服务端设置好);

7 / 22

页眉 2、服务端点击“开始监听”,客户端点击“连接”;

3、客户端在消息框内输入消息,点击“发送”,则消息发送到服务端,; 4、服务端接收并且在“接收到的消息”框里显示消息与发送消息时的日期; 注:客户端与服务端均能断开连接。 一、

UDP发送端、UDP接收端:

1、 用户打开UDP发送端并且输入目标IP、需发送的消息; 2、 点击“发送按钮”;

3、 接收端点击“接收”则接收到消息。

程序源代码;

Tcp服务端:

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms; using System.Net;

using System.Net.Sockets; namespace TCP服务端 {

public partial class TcpServerForm : Form {

private Socket _server; private Socket _client;

8 / 22

搜索更多关于: 上海大学 计算机网络 实验报告 的文档
上海大学 计算机网络 实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c8xpve2suua7d82u9zjlx7yogl1itcy00ire_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top