I would like a utility that would allow me to send/receive tcp and udp messages as a client or server, assemble packets, set responses, etc... Preferably on Windows. Please let me know if you've seen anything like this. THANKS!
views:
46answers:
2Why don't you try the TcpClient and TcpListener in System.Net in one of the .NET languages? It is very simple to use these classes to implement a client/server system for your own.
//Server Binding
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 2015); serverSocket.Bind(ipEndPoint);
//Begin Recceive from any client IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0); EndPoint epSender = (EndPoint)ipeSender; serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnNetworkBytesReceived), epSender);
private void OnNetworkBytesReceived(IAsyncResult ar) { IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0); EndPoint epSender = (EndPoint)ipeSender; int BytesRead = serverSocket.EndReceiveFrom(ar, ref epSender); //parse your data ParseNetworkBytes(BytesRead, epSender); serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnNetworkBytesReceived), epSender);
}//OnNetworkBytesReceived()
//for sending to client Byte[] byteDataTemp = msg.messagePacketByLength(i, Constants.MAXSENDBUFFERSIZE); serverSocket.BeginSendTo(byteDataTemp, 0, byteDataTemp.Length, SocketFlags.None, epRcvr, new AsyncCallback(OnSend), null);
private void OnSend(IAsyncResult ar) { try { lock (serverSocket) { serverSocket.EndSendTo(ar); } } catch (ObjectDisposedException objexp) {
}
catch (Exception exp)
{
}
}//OnSend()