private void suckit() //线程同步方法
{
IPAddress theIP = IPAddress.Parse("127.0.0.1");
IPEndPoint theServer = new IPEndPoint(theIP,8888);
theSock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); theSock.Bind(theServer);
theSock.Listen(50);
show1.Text = "Listenning port......";
accsock = theSock.Accept();
if(accsock.Connected)
{
Byte[] sendStr = new Byte[512];
NetworkStream nS = new NetworkStream(accsock);
nS.Read(sendStr,0,sendStr.Length);
string Str = System.Text.Encoding.BigEndianUnicode.GetString(sendStr);
MessageBox.Show(Str);
}private void send() //发送数据代码
{
try
{
Byte[] sendStr = new Byte[512];
string Str = "xxxx";
NetworkStream nS = new NetworkStream(accsock);
sendStr = System.Text.Encoding.BigEndianUnicode.GetBytes(Str.ToCharArray());
nS.Write(sendStr,0,sendStr.Length);
f.Text = "sent";
}
catch(Exception ex)
{
f.Text = ex.ToString();
}
}当连接成功后,执行send方法发送数据流,可程序什么也接收不到,也就是说nS.Read(sendStr,0,sendStr.Length);下面的代码不会执行,请问这是为什么?谢谢!
{
IPAddress theIP = IPAddress.Parse("127.0.0.1");
IPEndPoint theServer = new IPEndPoint(theIP,8888);
theSock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); theSock.Bind(theServer);
theSock.Listen(50);
show1.Text = "Listenning port......";
accsock = theSock.Accept();
if(accsock.Connected)
{
Byte[] sendStr = new Byte[512];
NetworkStream nS = new NetworkStream(accsock);
nS.Read(sendStr,0,sendStr.Length);
string Str = System.Text.Encoding.BigEndianUnicode.GetString(sendStr);
MessageBox.Show(Str);
}private void send() //发送数据代码
{
try
{
Byte[] sendStr = new Byte[512];
string Str = "xxxx";
NetworkStream nS = new NetworkStream(accsock);
sendStr = System.Text.Encoding.BigEndianUnicode.GetBytes(Str.ToCharArray());
nS.Write(sendStr,0,sendStr.Length);
f.Text = "sent";
}
catch(Exception ex)
{
f.Text = ex.ToString();
}
}当连接成功后,执行send方法发送数据流,可程序什么也接收不到,也就是说nS.Read(sendStr,0,sendStr.Length);下面的代码不会执行,请问这是为什么?谢谢!
解决方案 »
- C# 下 spreadsheet 控件怎么用?就是用来加载一个Excel文件,然后Excel可以编辑。都需要引用什么dll,控件在工具栏的什么位置,希望可以说的
- C# 怎么设置鼠标光标为excel中的十字形
- C#新手,跪求用timer定时获取数据库内容
- C#发邮件21cn
- char[]怎么不能转换为string两次呢
- 跪地求帮助!!!关于“该进程无法访问文件”的问题!
- 请教有关DataGird的问题。
- C#.net中关于ActiveReport 输出到excel,请高手赐教
- 寻求web快速上传组件
- 请教:如何获得记录集的行数?
- 怎样将"2"格式化为"002"
- 如何在把DataGrid中的一个字段绑写到一个TextBox中
accsock.Connected的总是false.不执行读操作
//NetworkStream nS = new NetworkStream(accsock);