C#套接字将数据发送到客户端 [英] C# Sockets Send Data to client

查看:102
本文介绍了C#套接字将数据发送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我只是想知道为什么

Hey Guys,

I am just wondering why

telnet mail.someserver.com 110
+OK MAILSERVER ready.


以新行结束,就好像期望用户响应一样,但是当我使用


Ends on a new line as if it is expecting a user response, but when I use

//Send
mySocket.Send(myByte);

//Recive
Byte[] bRecive = new byte[1024];
int i = mySocket.Receive(bRecive, bRecive.Length, 0);
string sBuffer = Encoding.ASCII.GetString(bRecive);



回应是



The response is

telnet localhost 110
+OK ready.



我应该发送某种终止符或换行符\ r \ n,因为我在输入击键时我的应用程序崩溃了.

谢谢



should I send some kind of terminator or line break \r\n when I expect a user input because my app crashes when I enter a keystroke.

Thanks

推荐答案

您可以尝试使用此->

//发送

byte [] data = Encoding.ASCII.GetBytes(message);
soc.Send(data);

//接收

byte [] data1 =新的byte [1024];
int p = soc.Receive(data1);
message =";
message = Encoding.ASCII.GetString(data1,0,p);
you can try this->

//send

byte[] data = Encoding.ASCII.GetBytes(message);
soc.Send(data);

//receive

byte[] data1 = new byte[1024];
int p = soc.Receive(data1);
message = "";
message = Encoding.ASCII.GetString(data1, 0, p);


这篇关于C#套接字将数据发送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆