socket发送协议问题,,,,

lixin546 2008-11-05 10:19:23
我现在把结构体,序列化后再转换成byte数组,发送过去,但是对方接口只看到我连接上去了,没有收到任何数据,
我在本机测试,是可以发送和接收到数据的,请问各位大侠会是什么原因????我应该怎么定位这个问题????
...全文
49 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixin546 2008-11-05
  • 打赏
  • 举报
回复
急啊!!!!!!各位过路的帮顶啊!!!!!!!:-)
lixin546 2008-11-05
  • 打赏
  • 举报
回复
private void BeginSend()
{
//IP and Port
string ip = this.txtip.Text;
string port = this.txtport.Text;


IPAddress serverIp = IPAddress.Parse(ip);

int serverPort = Convert.ToInt32(port);

IPEndPoint iep = new IPEndPoint(serverIp, serverPort);

byte[] byteMessage;


try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

socket.Connect(iep);

//序列化,转成byte数组
byteMessage = getData();

//发送
int i = socket.Send(byteMessage);
//关闭socket
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
WriteLog("发送失败" + ex.ToString());
}

}

部分代码
lixin546 2008-11-05
  • 打赏
  • 举报
回复
在同一个套接字里面可以发送数据后再接收返回的数据么????
lixin546 2008-11-05
  • 打赏
  • 举报
回复
为什么???

[Quote=引用 3 楼 r_swordsman 的回复:]
不要关闭socket
[/Quote]
r_swordsman 2008-11-05
  • 打赏
  • 举报
回复
不要关闭socket

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧