| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 409 人关注过本帖
标题:[求助]数据流发送总出错
只看楼主 加入收藏
放歌
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-7-11
收藏
 问题点数:0 回复次数:0 
[求助]数据流发送总出错

private void Test1()
{
try
{
this.m_strNetAddress = "127.0.0.1";

m_nPort = 8081;

SocketInformation sInfo = new SocketInformation();

Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint epServer = new IPEndPoint(IPAddress.Parse(m_strNetAddress), m_nPort);
AsyncCallback onconnect = new AsyncCallback(OnConnect);
s.BeginConnect(epServer, onconnect, s);
(为什么总是连接不上?这几句有什么错误呢?)

int nOut = 0;
for(int i=0; i<this.nBufSize; i++)
buffer[i] = this.fileBuffer[this.iCurPosition+i];
nOut = s.Send(this.buffer );

this.iCurPosition += this.nBufSize;

}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}

}

public void OnConnect(IAsyncResult ar)
{
// Socket was the passed in object
Socket sock = (Socket)ar.AsyncState;
try
{
//sock.EndConnect( ar );
if (sock.Connected)
{
/*
byte[] abc = new byte[256];
for(int i=0; i<256; i++)
abc[i] = (byte)i;
///int error = sock.Send(abc, 0, 256, 0);
SetupRecieveCallback( sock );
*/
}
else
MessageBox.Show("Unable to connect to remote machine", "Connect Failed!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Unusual error during Connect!");
}
}

搜索更多相关主题的帖子: 数据 
2007-07-17 15:34
快速回复:[求助]数据流发送总出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016595 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved