62,272
社区成员
发帖
与我相关
我的任务
分享
public void Send(string p_message)
{
byte[] msg = System.Text.UTF8Encoding.UTF8.GetBytes(p_message);
try
{
if(socket!=null)
{
socket.Send(msg);
}
}
catch (SocketException ex)
{
//
}
}
public string RecvMessage()
{
string retvalue = String.Empty;
byte[] bytes = new byte[10240];
try
{
int n = 0;
do
{
n = socket.Receive(bytes);
if (n > 0)
{
retvalue += System.Text.UTF8Encoding.UTF8.GetString(bytes, 0, n);
}
} while (n == bytes.Length);
}
catch (SocketException e)
{
throw new Exception("消息错误");
}
return retvalue;
}