コード例 #1
0
 // Listening port : 5060
 public void StartListening_Sip(int port)
 {
     try {
         frm.Set_TextBox("Server StartListening_Sip: ");
         this.CipConnection = new CipConnection(this.frm);
         this.CipConnection.DataReceived += new EventHandler <CipDataReceivedEventArgs>(this.DataReceived);
         this.CipConnection.StartListening(port);
     } catch (Exception exception) {
         throw exception;
     }
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: tuandaodev/DoroSimulator
        public void Go_Send(int currentPort)
        {
            try
            {
                SipUri from = new SipUri(this.AppServerSipUri);

                string AlarmEndPointSipUri = "sip:contact@" + this.LocalIpAddress + ":" + currentPort;
                SipUri to = new SipUri(AlarmEndPointSipUri);

                SipRequest request = MessageRequest.CreateRequest(SipMethod.Message, to, from);
                Random     random  = new Random();

                int cSeq = random.Next(0, 10000);
                request.CSeq.SequenceNumber = cSeq;
                request.CSeq.Method         = SipMethod.Message;

                //int FreePort = DoroCommon.GetAvailablePort(5060);
                //Console.WriteLine(FreePort);

                IPAddress localIP = NetworkInformation.IPv4Address;

                ViaHeaderField via = new ViaHeaderField(new IPDomainPort(new IPEndPoint(localIP, currentPort)), TransportProtocol.Udp);
                via.ResponsePort = currentPort;
                request.ViaHeaders.Clear();
                request.ViaHeaders.Add(via);

                AlarmReq ar = new AlarmReq();
                ar.Ref = random.Next(0, 16).ToString();
                ar.Aty = "PI";
                ar.Tty = "C9300";
                ar.Tid = "7942098";
                ar.Inf = "Heartbeat";

                Console.WriteLine(ar.ToString());

                string body = SerializationClass.SerializeObject(ar, false, true, true);

                byte[] content = Encoding.UTF8.GetBytes(body);

                Console.WriteLine(content.ToString());

                request.Body          = content;
                request.ContentType   = new ContentTypeHeaderField(MediaType.Text, "text");
                request.ContentLength = content.Length;

                //Console.WriteLine(request.Body.ToString());

                IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(this.ServerIpAddress), this.ServerPort);
                IPEndPoint localEndpoint  = new IPEndPoint(localIP, currentPort);

                Protocol.DestinationTuple d = new Protocol.DestinationTuple(localEndpoint, remoteEndPoint);

                Console.WriteLine("Open Port: " + localIP + ":" + currentPort + " => Sent Message to " + this.ServerIpAddress + ":" + this.ServerPort);
                Set_TextBox("Open Port: " + localIP + ":" + currentPort + " => Sent Message to " + this.ServerIpAddress + ":" + this.ServerPort);

                //Protocol.DestinationTuple d = new Protocol.DestinationTuple(this.ServerIpAddress.ToString(), this.ServerPort);

                CipConnection cipConnection = new CipConnection(this);
                cipConnection.StartListening(currentPort);
                cipConnection.Send(request, d);

                Interlocked.Increment(ref CountConnection);
                Set_Status();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }