云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 上海大学 计算机网络 实验报告

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

  • 62 次阅读
  • 3 次下载
  • 2025/12/10 15:46:22

页眉 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

搜索更多关于: 上海大学 计算机网络 实验报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

页眉 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 ReceivedDat

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com