Avatar of Xmdy
Xmdy asked on

pc-pc using RTC in C#

I'm trying to create a simple client application for pc-pc communication using RTC in C#. I'm new to this kind of programming but wanna learn it, so i'll explain as easy understandable as possible.
I am using a Form1 where i initialize my rtc client _rtc.Initialize(). It contains methods for: clicking 2 buttons: 1 to listen for incomming connections and 2 to attempt a connection, as well as the ones for event notification, for media events and for session state change (RTC_IRTCEventNotification_Event_Event(etc..)  OnIRTCMediaEvent  OnIRTCSessionStateChangeEvent)

-my button1_Click method contains

_rtc.SetPreferredMediaTypes(receiveAudio | sendAudio | receiveVideo | sendVideo, true);
            _rtc.EventFilter = media | messaging;
            _rtc.IRTCEventNotification_Event_Event += new IRTCEventNotification_EventEventHandler(RTC_IRTCEventNotification_Event_Event);
            _rtc.ListenForIncomingSessions = RTC_LISTEN_MODE.RTCLM_BOTH;

-my button2_Click contains

_session = _rtc.CreateSession(RTC_SESSION_TYPE.RTCST_PC_TO_PC, null, null, 0);            
            _session.AddParticipant(adresaIP, nume);

I wrote here only the main code lines and skipped the ones where i get my parameters from.
I want the application to work as a server and a client or, not as a real server, only for the other client so the two pc's can communicate. I was expecting when i press my 1st button on one pc, after, press my 2nd button on other pc, the 2nd pc to attempt a connection to the 1st; I'm sure at some point some connection attempted because i heard _rtc.PlayRing from OnIRTCSessionStateChangeEvent(..) but i couldn't get my code back to that old stage.
Am i missing some hardware selection with a method i don't know about? or am i missing some code? or i got the wrong idea of how to make this work?
I didn't write here the contents of the 3 methods for event handling, media handling and state change but i think they are ok. If i should write more of my code here just tell me. Any answer would be appreciated, thanks.
I managed to make the application to answer an incoming session all the time by setting the _rtc.EventFilter = 0x01FFFFFF;
However, i hit other problem, can't send a message. My 1st client is listening:
_rtc.EventFilter = 0x01FFFFFF;
_rtc.ListenForIncomingSessions = RTC_LISTEN_MODE.RTCLM_BOTH;
_rtc.IRTCEventNotification_Event_Event += new IRTCEventNotification_EventEventHandler(RTC_IRTCEventNotification_Event_Event);

while my 2nd client is connecting:
_session = _rtc.CreateSession(RTC_SESSION_TYPE.RTCST_PC_TO_PC, null, null, 0);
_session.AddParticipant(adresaIP, nume);

the 1st client answers the incoming session using _session.Answer(); but _session is still null after _sessionAnswer();. It should be so? The problem comes when i try sending a message after the session is answered and i get a NullRefereneException for the _session.SendMessage(msgHeader, msg, 0); line. Is the session not created? Should i create the session on my 1st listening client? adding the line in 1st client listening
_session = _rtc.CreateSession(RTC_SESSION_TYPE.RTCST_PC_TO_PC, null, null, 0);
sends me into another exception for the same _session.SendMessage.. line with value 0x80EE0029 which means "The client is already initialized." so i think the session should be created on answer not need to be added before.
Where am i wrong?

I noticed that the listening pc is actually never answering a call, so whole problem might resume to _session.Answer(); which is never working. Anyone know any issue with answering an incoming pc-pc call? please let me know, ty

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck