How to use Php Backend with C# Front End for a messaging App?

So I am totally confused on what to do. So I am creating a messaging app for my project which also uses a Php Api, so now i want to implement that but I am totally confused on how to do it?
So here are my ideas
Idea 1:
Use Php as backend and use Api (CRUD) to check for messages sent by the client to another client (There will be around 100-500 Users)

Idea 2:
Use C# sockets. When User comes online he will connect to server and store its Ip + port in database and using that client will communication (Havent tried this just assuming it will work)

So which one is better/worse and what is your solution

Tagged:

Best Answer

  • Accepted Answer

    Hey
    Ok so here is my solution to my own problem.

    If the users are less users then u can go with REST but for an efficient performance go with Sockets I changed from Php to ASP Net Signal R backend. And with a little help from tutorials and documentation you are good to go

Answers

  • alexgealexge FRMember
    edited January 2017

    @HussainMurtaza urtaza
    If it's instant chat messaging, it's better to use the C# Sockets for " real-time ".
    For me, the plus to use C# sockets is you can know which users are connected to the socket server. With Http protocol, you can't know.

    You don't need to store IP and port. You need to identify the client, so just request identification. (nickname for example).

    Now you know:

    • Users connected
    • Users nicknames.

    With theses informations, if a user send to a connected user a message, your socket server will receive the message and will transmit to the good recipient.
    If user isn't connected, you can store it in database and when user is connected you send offline messages to him.

    Hope this helps.

  • Well for c# sockets I would require a server and I have a php server will that work.
  • Sorry for asking too kiddy question. It's my first time creating the chatting app hence I am too confused about this.
  • alexgealexge FRMember
    edited January 2017

    @HussainMurtaza Ow.. yea you can create sockets with PHP. You can use PHP command line interface to start your socket server.

    Check here.

  • Ok one more thing if I wanted to deploy this on a server then will it automatically start this.
    Also I am using slim framework for rest api
  • alexgealexge FRMember
    edited January 2017

    @HussainMurtaza
    The php script will run until you close the page. You need to keep 24/24... bad thing.

    Using a php API (JSON for example) is better for your case.

  • Yeah hence I am planning for stateless messaging the only issue is that a lot of over head I guess
  • Any other solution you might wanna share?
  • Any other solution you might wanna share?
  • HarbHarb USMember ✭✭

    Hello there!
    I am here with the same question.
    I would like to implement a one-one messaging solution, basically it is a chat. I have c# client - Xamarin forms. And - right now - a PHP backend. How would you efficiently implement this?
    Probable solution:

    • Polling if Server has new message: I think this is a bad idea, as it does not scale well.
    • Socket for both users? Is it okay to rely on a connection and not being stateless?
  • HussainMurtazaHussainMurtaza USMember
    Accepted Answer

    Hey
    Ok so here is my solution to my own problem.

    If the users are less users then u can go with REST but for an efficient performance go with Sockets I changed from Php to ASP Net Signal R backend. And with a little help from tutorials and documentation you are good to go

Sign In or Register to comment.