我做的一个telnet程序,发送命令有问题!
代码地址:http://www.fengyun4.com/telnet.zip
在发送命令以后,再接收的时候程序就死掉了?
不知道为什么!
连接以后的画面和再接收的程序是一样的呀?为什么呢?
请帮帮我!我不知道从那里找原因,或者我的思路有问题
很小的程序~
拜托各位啦!
捧场有分!
问题点数:100、回复次数:15Top
1 楼iyiduhsoad(一第数倒)回复于 2002-05-13 00:21:19 得分 80
捧场捧场,wuye是风云四里哪个玩家??
btw:如果程序很小,就贴出来。
telnet us.fengyun.com 6666
telnet fengyun.com 6666
人太多了,上不去,sigh!Top
2 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 09:07:00 得分 0
主要是贴出来看不清楚,所以没贴
我是风云的梦儿(mmud)
风云4 我已经不玩了!现在玩.net!呵呵Top
3 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 09:11:23 得分 0
完整代码如下:请大家帮帮忙呀!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
namespace telnet
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private TcpClient tc;
private NetworkStream ns;
// private bool TrueNs;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(32, 16);
this.label1.TabIndex = 0;
this.label1.Text = "IP:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(48, 8);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "202.95.18.95";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 8);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(48, 21);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "3333";
//
// button1
//
this.button1.Location = new System.Drawing.Point(216, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 3;
this.button1.Text = "连接";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox1
//
this.richTextBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.richTextBox1.Location = new System.Drawing.Point(0, 40);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(460, 200);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "";
//
// textBox3
//
this.textBox3.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.textBox3.Location = new System.Drawing.Point(8, 248);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(380, 21);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "mmud";
//
// button2
//
this.button2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.button2.Location = new System.Drawing.Point(396, 248);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 6;
this.button2.Text = "发送";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.textBox3,
this.richTextBox1,
this.button1,
this.textBox2,
this.textBox1,
this.label1});
this.Name = "Form1";
this.Text = "Form1";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
this.richTextBox1.Text="正在连接"+this.textBox1.Text;
Record();
//Record1();
}
private void Record()
{
try
{
tc=new TcpClient(this.textBox1.Text,Convert.ToInt16(this.textBox2.Text));
Record1();
// NetworkStream ns = tc.GetStream();
}
catch(Exception es)
{
this.richTextBox1.Text=es.ToString();
}
// byte[] ReadBuffer=new byte[64024];
// //NetworkStream ns=tc.GetStream();
// try
// {
// int StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
// string ReturnValue=System.Text.Encoding.Default.GetString(ReadBuffer);
// this.richTextBox1.Text=ReturnValue.ToString().Replace("[2;37;0m;","");
//
//
// }
// catch(Exception e)
// {
// this.richTextBox1.Text=e.ToString();
// }
//Record1();
}
private void Record1()
{
byte[] ReadBuffer=new byte[tc.ReceiveBufferSize];
MessageBox.Show(tc.ReceiveBufferSize.ToString());
NetworkStream ns=tc.GetStream();
try
{
if(ns.CanRead)
{
int StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
string ReturnValue=System.Text.Encoding.Default.GetString(ReadBuffer);
this.richTextBox1.Text=ReturnValue.ToString().Replace("[2;37;0m;","");
}
else
{
this.richTextBox1.Text="不能读";
}
}
catch(Exception e)
{
this.richTextBox1.Text=e.ToString();
}
}
private void SendCommand(string Command)
{
byte[] WriteBuffer=System.Text.Encoding.Default.GetBytes(Command);
try
{
NetworkStream ns=tc.GetStream();
ns.Write(WriteBuffer,0,WriteBuffer.Length);
byte[] ReadBuffer=new byte[tc.ReceiveBufferSize];
//MessageBox.Show(tc.ReceiveBufferSize.ToString());
int StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
string ReturnValue=System.Text.Encoding.Default.GetString(ReadBuffer);
this.richTextBox1.Text=ReturnValue.ToString().Replace("[2;37;0m;","");
//return true;
}
catch(Exception e)
{
this.richTextBox1.Text=e.ToString();
//return false;
}
//return true;
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// if (TrueNs)
// {
//
// ns.Close();
// }
// tc.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
// if (SendCommand(this.textBox3.Text))
// {
// Record1();
// }
SendCommand(this.textBox3.Text.ToString());
}
}
}
Top
4 楼iyiduhsoad(一第数倒)回复于 2002-05-13 10:09:48 得分 0
原来是站长呀,呵呵,建议增开.net版,偶可以去灌水。
昨天我大略看了一下,主要是取不到数据。
如你所说把NetworkStream ns=tc.GetStream();这句放到
Record1函数里面,就没问题了吗?肯定吗?那得到的结果是
什么?你使用的是现在默认的ip及port,如果我使用相同的,
也能取到同样的结果吗?
如你现在的程序,能正常运行了吗??
如果仅仅是把NetworkStream ns=tc.GetStream();这句放到
Record1函数里面就没问题的话,
那你程序中ns赋值未在record1前呀,放在前面应该就可以了。
btw:现在在公司,没有.net环境,晚上帮你调。
Top
5 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 10:23:25 得分 0
我的网站是风云的,放c#也没人看!呵呵!
我把NetworkStream ns=tc.GetStream();这句放到
Record1函数里面,肯定没问题的,返回的结果也是正确的
你也可以连的,是一个风云mud,连上去一看就知道了!
我如果把他放到函数里面是能正常运行的,
如果放到函数外面,即使把ns赋值放到record1前也不行!
所以才不理解!
这个问题虽然我不明白,但是放到函数里面也能用!
最主要的问题是我没次发一条命令然后再取服务器返回的数据
程序就死了,我不太会用.net调试的方法,不知道怎么下手
调试了!唉!昨天已经搞了一晚上了,苦呀!Top
6 楼iyiduhsoad(一第数倒)回复于 2002-05-13 10:32:05 得分 0
今晚陪你一起苦,哎........Top
7 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 10:34:19 得分 0
多谢多谢!
有qq嘛!上qq聊聊吧!
我的是9376412Top
8 楼jdpopo(破破)回复于 2002-05-13 15:35:28 得分 10
我捧!Top
9 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 16:50:51 得分 0
顶Top
10 楼wuye(午夜循环(QQ:260968))回复于 2002-05-13 23:40:52 得分 0
郁闷啊!
又是一个晚上没搞定!
没有人能帮忙吗?Top
11 楼wuye(午夜循环(QQ:260968))回复于 2002-05-14 09:09:13 得分 0
死程序的问题终于解决了!
但是发送命令以后怎么不能接受到正确的返回数据呢?
有人做过类似telnet的程序吗?
给我说说思路撒!Top
12 楼sagood(sagood)回复于 2002-05-14 10:08:34 得分 10
我根据你的代码,编译后通过,运行如下:
??[2J [1m [32m ;, ;, ;, ;,,,,,,,,;, ,,,,,,,,;, ;; ;; ;; ;; ;; ,,;;,,;;,,;;,;, ;;', ,;,;; , ,,,,,,,,,,,;, ;; ;; ;; ;; ';;' ;; '''''';;''''''' ;; ;; ;; ;; ,;;, ;; ;; ', ;; ;''';' ;; ;'';;;; ,;' ';, ;; , ;; ' ' ;; ; ,;,,,,,,;;, ';''''''''''' ,' ';;' ';'''' ;' [36m 狂[1m[1;31m风[36m一翻滚, 何处不是[1m[1;31m云[36m。 郑州风云世纪珍藏版 官方网站[1;33m http://202.95.18.95 [36m支持网站[1;33m http://www.fengyun4.com[30m [2;37;0m [1;32m郑州风云已经运行了六天二十小时五十一分四十九秒。
[2;37;0m[1;32m现在是北京时间二零零二年五月十四日十点八分 星期二。
[2;37;0m[1;31m您是郑州风云开站以来的第[1;36m一千三百二十八万九千四百五十一[2;37;0m[1;31m位访问者。
[2;37;0m[1;31m本风云共有[2;37;0m[1;36m二万一千四百六十六[2;37;0m[1;31m个玩家注册了档案。
[2;37;0m[1;31m郑州风云目前共有[2;37;0m[1;36m六十一[2;37;0m[1;31m位玩家游戏中、及[2;37;0m[1;36m四[2;37;0m[1;31m位尝试连线者。
本游戏最大人数为: [2;37;0m[1;36m300人
[2;37;0m您的英文名字:
Top
13 楼wuye(午夜循环(QQ:260968))回复于 2002-05-14 10:09:47 得分 0
自己终于解决了!
多谢iyiduhsoad(一第数倒)的帮助!
完结加分啦!Top
14 楼sagood(sagood)回复于 2002-05-14 10:10:39 得分 0
但是在输入名字后,就死了
Top
15 楼sagood(sagood)回复于 2002-05-14 10:11:02 得分 0
但是在输入名字后,就死了
Top




