Hi all,
Is it possible to communicate FreeRTOS Windows Demo with any windows app on local PC?
I use FreeRTOS Socket Demo in the link below. I am trying to communicate this app by using a Socket connection with the other C# Console App in same PC.
It is my method for socket listening code "vCreateTCPServerSocket:"
void vCreateTCPServerSocket()
{
struct freertos_sockaddr xClient, xBindAddress;
Socket_t xListeningSocket, xConnectedSocket;
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
const BaseType_t xBacklog = 20;
xListeningSocket = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP);
configASSERT(xListeningSocket != FREERTOS_INVALID_SOCKET);
FreeRTOS_setsockopt(xListeningSocket,0,FREERTOS_SO_RCVTIMEO,&xReceiveTimeOut,sizeof(xReceiveTimeOut));
//xBindAddress.sin_addr = FreeRTOS_inet_addr("192.168.1.15");
//xBindAddress.sin_addr = FreeRTOS_inet_addr_quick(192,168,1,15);
xBindAddress.sin_port = FreeRTOS_htons(3002);
socklen_t xSize = sizeof(xClient);
BaseType_t returnV al_bind = FreeRTOS_bind(xListeningSocket, &xBindAddress, sizeof(xBindAddress));
//binding successfully
BaseType_t returnVal_listen = FreeRTOS_listen(xListeningSocket, xBacklog);
//listening successfully
for (;; )
{
xConnectedSocket = FreeRTOS_accept(xListeningSocket, &xClient, &xSize);
//cannot connect succesfully
configASSERT(xConnectedSocket != FREERTOS_INVALID_SOCKET);
if (xConnectedSocket != FREERTOS_INVALID_SOCKET)
{
//Sending part.
}
}
}
}
But there is a problem when FreeRTOS accepting and taking the xConnected socket.
Here is my C# Client, Console_Client():
public static void Console_Client()
{
try
{
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddr = IPAddress.Parse("192.168.1.15");
IPEndPoint localEndPoint = new IPEndPoint(ipAddr, 3002);
Socket sender = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
while (true)
{
try
{
Console.WriteLine("Bağlanmaya çalışıyor..");
sender.Connect(localEndPoint);
Console.WriteLine("Socket connected to -> {0} ",
sender.RemoteEndPoint.ToString());
byte[] messageSent = Encoding.ASCII.GetBytes("Test Client<EOF>");
int byteSent = sender.Send(messageSent);
sender.Shutdown(SocketShutdown.Both);
sender.Close();
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
Here is my C# Server, Console_Server():
public static void Console_Server()
{
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddr = IPAddress.Parse("192.168.1.15");
IPEndPoint localEndPoint = new IPEndPoint(ipAddr, 3002);
Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
try
{
listener.Bind(localEndPoint);
listener.Listen(10);
Console.WriteLine("Waiting connection ... ");
Socket clientSocket = listener.Accept();
while (true)
{
byte[] bytes = new Byte[1024];
string data = null;
while (true)
{
int numByte = clientSocket.Receive(bytes);
data += Encoding.ASCII.GetString(bytes,0, numByte);
if (data.IndexOf("<EOF>") > -1)
break;
}
Console.WriteLine("Text received -> {0} ", data);
byte[] message = Encoding.ASCII.GetBytes("Test Server");
clientSocket.Send(message);
//clientSocket.Shutdown(SocketShutdown.Both);
//clientSocket.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
Despite this Console_Client communicating with my Console_Server normally it is not communicate with the FreeRTOS side. Is there any hardware-dependent issue that I don’t know or Is it possible to communicate FreeRTOS Socket with Console Socket in the Windows PC.