├── .gitignore
├── README.md
├── build.xml
├── build
├── built-jar.properties
└── classes
│ ├── .netbeans_automatic_build
│ ├── .netbeans_update_resources
│ └── udpserver
│ ├── Request.class
│ ├── UDPServer.class
│ ├── ackRequest.class
│ ├── byeRequest.class
│ ├── callDetails.class
│ ├── cancelRequest.class
│ ├── inviteRequest.class
│ ├── okRequest.class
│ ├── registerRequest.class
│ ├── requestTerminatedRequest.class
│ └── ringingRequest.class
├── docs
├── 1.oxps
├── 2.oxps
├── 3.oxps
├── 4.oxps
├── 5.oxps
├── Part 1.docx
├── Part 2.doc
├── Part 3.docx
├── Part 4.docx
├── Part 5.docx
└── VoIP Project.pdf
├── images
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
├── 6.png
├── 7.png
├── netbeans.png
└── phoner.png
├── manifest.mf
├── nbproject
├── build-impl.xml
├── genfiles.properties
├── private
│ ├── config.properties
│ ├── private.properties
│ └── private.xml
├── project.properties
└── project.xml
└── src
└── udpserver
├── Request.java
├── UDPServer.java
├── ackRequest.java
├── byeRequest.java
├── callDetails.java
├── cancelRequest.java
├── inviteRequest.java
├── okRequest.java
├── registerRequest.java
├── requestTerminatedRequest.java
└── ringingRequest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VoIP Communication Using SIP
2 |
3 | The VoIP COMMUNICATION USING SIP is a server based software that creates and manages a session, where a session is considered an exchange of data between an association of participants. It provides user friendly environment for users to communicate between themselves.
4 |
5 | It uses SIP (Session Initiation Protocol) which is one of the most common protocol used in VoIP technology. VoIP is a technology that allows us to deliver voice and multimedia content over the internet. It is one of the cheapest way to communicate anytime anywhere with internet availability.
6 |
7 |
8 | This is a JAVA based server program which handles clients. The software makes excessive use of JAVA Socket API to receive requests and forward respective responses. It maintains detail of registered clients i.e IP address and local port and their numbers. Upon recieveing a call request by any registered user, it generates an appropriate SIP response and forwards it its destination. This software can also act as a proxy server that can communicate as a proxy with another instance of same software running on different machine.
9 |
10 | This readme contains screenshots of working of the software and basic guidelines of its usage. This is an introduction as well as a step by step method of how to use this software.
11 |
12 | ## Table of contents
13 |
14 | - [Installation](#installation)
15 | - [Prerequisites](#prerequisites)
16 | - [Using NetBeans IDE](#using-netbeans-ide)
17 | - [Technologies Used](#technologies-used)
18 | - [Features](#features)
19 | - [Registration of Users](#register)
20 | - [Normal Flow](#normal)
21 | - [Cancellation Process](#cancel)
22 | - [When Busy](#busy)
23 | - [Installation and Usage Guide](#guide)
24 | - [Links](#links)
25 |
26 | ## Installation
27 |
28 | ### Prerequisites
29 |
30 | 1. NetBeans 8.0.2 IDE
31 | 2. JDK 1.6 or higher
32 | 3. Phoner/Jitsi (Virtual phones) or any IP enabled Phone
33 | 4. Windows (for client if using Phoner)
34 | 5. A server
35 |
36 | ### Using NetBeans 8.0.2 IDE
37 |
38 | 1. Create a new Project in NetBeans
39 | 2. Fork this repo
40 | 3. Copy all the files in this repo to project's folder
41 | 4. Run the project (Specific details later in this readme)
42 |
43 |
44 | ### Technologies Used
45 |
46 | 1. JAVA Socket API
47 | 2. SIP Protocol (RFC3261)
48 | 3. UDP (User Datagram Protocol)
49 |
50 | ## Features
51 |
52 | ### Registration Of Users
53 |
54 | A user sends a REGISTER request to the server. The request includes user’s contact list. The SIP Server validates the user’s credentials and if it succeeds then user is successfully registered and server replies with 200 OK response.
55 |
56 | ### Normal Flow
57 |
58 | In this flow of control, the caller makes a call through an INVITE request which is handled by the server. The server figures out the correct recipient of the call and forwards it. It also sends back a TRYING 100 response back to the caller. The receiver recognizes the INVITE message and there is a ringing bell on the phone of the receiver. He picks up the call and a successful RTP connection is established between both the users. Any user can drop the call by sending a BYE request to the other user. The other user sends an appropriate ACK response and the session terminates.
59 |
60 | ### Cancellation Process
61 |
62 | When the user who is calling, ends the call then a CANCEL request is sent to the server. The server forwards the CANCEL request to the receiver. Receiver sends an 200 OK and a 487 REQUEST TERMINATED response. The session is then cancelled successfully.
63 |
64 | ### When Busy
65 |
66 | When the receiver terminates the call during the ringing phase, then the caller receives 486 BUSY HERE response. In this scenario, reciever is busy and sends a 486 BUSY HERE response to caller’s INVITE. Note that the non 2xx response is acknowledged on a hop-by-hop basis instead of end-to-end. Also note that many SIP UAs will not return a 486 response, as they have multiple lines and other features.
67 |
68 | ## Installation And Usage Guide
69 |
70 | 1. DOWNLOAD PHONER ON CLIENT
71 | 
72 | 2. SET UP NETBEANS 8.0.2 or later with JDK 1.6 or later
73 | 
74 | 3. RUN THE CODE ON A SERVER SPECIFYING THE PORT AND IP
75 | 
76 | clients will register one by one...
77 | 
78 | 4. RUN PHONER ON CLIENT COMPUTER AND SET SERVER IP AS REGISTRAR
79 | 5. NOW DIAL THE NUMBER OF ANY REGISTERED USER AND CALL
80 | 
81 | 6. RTP SESSION IS ETABLISHED WHEN ‘CONNECTED’ IS DISPLAYED
82 | 
83 | 7. CLICK THE RED ‘END CALL’ WHEN FINISHED TALKING
84 | 8. LOG SCREEN DURING ‘BUSY HERE’
85 | 
86 | 9. LOG SCREEN DURING NORMAL FLOW
87 | 
88 | 10. LOG SCREEN DURING CANCELATION
89 | 
90 |
91 | ## Links
92 |
93 | Visit me: [Rajat Saxena](http://www.rajatsaxena.me/)
94 |
95 | Contact me:
96 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Builds, tests, and runs the project UDPServer.
12 |
13 |
73 |
74 |
--------------------------------------------------------------------------------
/build/built-jar.properties:
--------------------------------------------------------------------------------
1 | #Mon, 11 Jul 2016 15:39:34 +0530
2 |
3 |
4 | /home/bloodphoenix/NetBeansProjects/UDPServer=
5 |
--------------------------------------------------------------------------------
/build/classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/.netbeans_automatic_build
--------------------------------------------------------------------------------
/build/classes/.netbeans_update_resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/.netbeans_update_resources
--------------------------------------------------------------------------------
/build/classes/udpserver/Request.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/Request.class
--------------------------------------------------------------------------------
/build/classes/udpserver/UDPServer.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/UDPServer.class
--------------------------------------------------------------------------------
/build/classes/udpserver/ackRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/ackRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/byeRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/byeRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/callDetails.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/callDetails.class
--------------------------------------------------------------------------------
/build/classes/udpserver/cancelRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/cancelRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/inviteRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/inviteRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/okRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/okRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/registerRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/registerRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/requestTerminatedRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/requestTerminatedRequest.class
--------------------------------------------------------------------------------
/build/classes/udpserver/ringingRequest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/build/classes/udpserver/ringingRequest.class
--------------------------------------------------------------------------------
/docs/1.oxps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/1.oxps
--------------------------------------------------------------------------------
/docs/2.oxps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/2.oxps
--------------------------------------------------------------------------------
/docs/3.oxps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/3.oxps
--------------------------------------------------------------------------------
/docs/4.oxps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/4.oxps
--------------------------------------------------------------------------------
/docs/5.oxps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/5.oxps
--------------------------------------------------------------------------------
/docs/Part 1.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/Part 1.docx
--------------------------------------------------------------------------------
/docs/Part 2.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/Part 2.doc
--------------------------------------------------------------------------------
/docs/Part 3.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/Part 3.docx
--------------------------------------------------------------------------------
/docs/Part 4.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/Part 4.docx
--------------------------------------------------------------------------------
/docs/Part 5.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/Part 5.docx
--------------------------------------------------------------------------------
/docs/VoIP Project.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/docs/VoIP Project.pdf
--------------------------------------------------------------------------------
/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/1.png
--------------------------------------------------------------------------------
/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/2.png
--------------------------------------------------------------------------------
/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/3.png
--------------------------------------------------------------------------------
/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/4.png
--------------------------------------------------------------------------------
/images/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/5.png
--------------------------------------------------------------------------------
/images/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/6.png
--------------------------------------------------------------------------------
/images/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/7.png
--------------------------------------------------------------------------------
/images/netbeans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/netbeans.png
--------------------------------------------------------------------------------
/images/phoner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/images/phoner.png
--------------------------------------------------------------------------------
/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | X-COMMENT: Main-Class will be added automatically by build
3 |
4 |
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 | Must set src.dir
227 | Must set test.src.dir
228 | Must set build.dir
229 | Must set dist.dir
230 | Must set build.classes.dir
231 | Must set dist.javadoc.dir
232 | Must set build.test.classes.dir
233 | Must set build.test.results.dir
234 | Must set build.classes.excludes
235 | Must set dist.jar
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 | Must set javac.includes
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 | No tests executed.
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 | Must set JVM to use for profiling in profiler.info.jvm
716 | Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
717 |
718 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 | Must select some files in the IDE or set javac.includes
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 |
953 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 | To run this application from the command line without Ant, try:
995 |
996 | java -jar "${dist.jar.resolved}"
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 |
1024 |
1025 |
1026 |
1027 |
1032 |
1033 |
1034 |
1035 |
1036 |
1037 |
1038 |
1039 |
1040 |
1041 |
1042 |
1043 | Must select one file in the IDE or set run.class
1044 |
1045 |
1046 |
1047 | Must select one file in the IDE or set run.class
1048 |
1049 |
1050 |
1055 |
1056 |
1057 |
1058 |
1059 |
1060 |
1061 |
1062 |
1063 |
1064 |
1065 |
1066 |
1067 |
1068 |
1069 |
1070 |
1071 |
1072 |
1073 |
1074 | Must select one file in the IDE or set debug.class
1075 |
1076 |
1077 |
1078 |
1079 | Must select one file in the IDE or set debug.class
1080 |
1081 |
1082 |
1083 |
1084 | Must set fix.includes
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1096 |
1099 |
1100 | This target only works when run from inside the NetBeans IDE.
1101 |
1102 |
1103 |
1104 |
1105 |
1106 |
1107 |
1108 |
1109 | Must select one file in the IDE or set profile.class
1110 | This target only works when run from inside the NetBeans IDE.
1111 |
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 | This target only works when run from inside the NetBeans IDE.
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 | This target only works when run from inside the NetBeans IDE.
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 |
1163 |
1164 |
1165 |
1166 |
1167 |
1168 |
1169 |
1170 | Must select one file in the IDE or set run.class
1171 |
1172 |
1173 |
1174 |
1175 |
1176 | Must select some files in the IDE or set test.includes
1177 |
1178 |
1179 |
1180 |
1181 | Must select one file in the IDE or set run.class
1182 |
1183 |
1184 |
1185 |
1186 | Must select one file in the IDE or set applet.url
1187 |
1188 |
1189 |
1190 |
1195 |
1196 |
1197 |
1198 |
1199 |
1200 |
1201 |
1202 |
1203 |
1204 |
1205 |
1206 |
1207 |
1208 |
1209 |
1210 |
1211 |
1212 |
1213 |
1214 |
1215 |
1216 |
1217 |
1218 |
1219 |
1220 |
1221 |
1222 |
1223 |
1224 |
1225 |
1226 |
1227 |
1228 |
1229 |
1230 |
1231 |
1232 |
1233 |
1234 |
1239 |
1240 |
1241 |
1242 |
1243 |
1244 |
1245 |
1246 |
1247 |
1248 |
1249 |
1250 |
1251 |
1252 |
1253 |
1254 |
1255 |
1256 |
1257 |
1258 |
1259 |
1260 |
1261 |
1262 |
1263 |
1264 |
1265 | Must select some files in the IDE or set javac.includes
1266 |
1267 |
1268 |
1269 |
1270 |
1271 |
1272 |
1273 |
1274 |
1275 |
1276 |
1277 |
1282 |
1283 |
1284 |
1285 |
1286 |
1287 |
1288 |
1289 | Some tests failed; see details above.
1290 |
1291 |
1292 |
1293 |
1294 |
1295 |
1296 |
1297 |
1298 | Must select some files in the IDE or set test.includes
1299 |
1300 |
1301 |
1302 | Some tests failed; see details above.
1303 |
1304 |
1305 |
1306 | Must select some files in the IDE or set test.class
1307 | Must select some method in the IDE or set test.method
1308 |
1309 |
1310 |
1311 | Some tests failed; see details above.
1312 |
1313 |
1314 |
1319 |
1320 | Must select one file in the IDE or set test.class
1321 |
1322 |
1323 |
1324 | Must select one file in the IDE or set test.class
1325 | Must select some method in the IDE or set test.method
1326 |
1327 |
1328 |
1329 |
1330 |
1331 |
1332 |
1333 |
1334 |
1335 |
1336 |
1337 |
1342 |
1343 | Must select one file in the IDE or set applet.url
1344 |
1345 |
1346 |
1347 |
1348 |
1349 |
1350 |
1355 |
1356 | Must select one file in the IDE or set applet.url
1357 |
1358 |
1359 |
1360 |
1361 |
1362 |
1363 |
1364 |
1369 |
1370 |
1371 |
1372 |
1373 |
1374 |
1375 |
1376 |
1377 |
1378 |
1379 |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 |
1386 |
1387 |
1388 |
1389 |
1390 |
1391 |
1392 |
1393 |
1394 |
1395 |
1396 |
1397 |
1398 |
1399 |
1400 |
1401 |
1402 |
1403 |
1404 |
1405 |
1406 |
1407 |
1408 |
1409 |
1410 |
1411 |
1412 |
1413 |
1414 |
--------------------------------------------------------------------------------
/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=6a2bba97
2 | build.xml.script.CRC32=41797c35
3 | build.xml.stylesheet.CRC32=8064a381@1.75.2.48
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=6a2bba97
7 | nbproject/build-impl.xml.script.CRC32=20596b64
8 | nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
9 |
--------------------------------------------------------------------------------
/nbproject/private/config.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srajat/UDP-SIP-Server/3437712624a3f90a0a36150ffc993da27040a353/nbproject/private/config.properties
--------------------------------------------------------------------------------
/nbproject/private/private.properties:
--------------------------------------------------------------------------------
1 | compile.on.save=true
2 | do.depend=false
3 | do.jar=true
4 | javac.debug=true
5 | javadoc.preview=true
6 | user.properties.file=/home/bloodphoenix/.netbeans/8.0.2/build.properties
7 |
--------------------------------------------------------------------------------
/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | annotation.processing.enabled=true
2 | annotation.processing.enabled.in.editor=false
3 | annotation.processing.processors.list=
4 | annotation.processing.run.all.processors=true
5 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
6 | application.title=UDPServer
7 | application.vendor=bloodphoenix
8 | build.classes.dir=${build.dir}/classes
9 | build.classes.excludes=**/*.java,**/*.form
10 | # This directory is removed when the project is cleaned:
11 | build.dir=build
12 | build.generated.dir=${build.dir}/generated
13 | build.generated.sources.dir=${build.dir}/generated-sources
14 | # Only compile against the classpath explicitly listed here:
15 | build.sysclasspath=ignore
16 | build.test.classes.dir=${build.dir}/test/classes
17 | build.test.results.dir=${build.dir}/test/results
18 | # Uncomment to specify the preferred debugger connection transport:
19 | #debug.transport=dt_socket
20 | debug.classpath=\
21 | ${run.classpath}
22 | debug.test.classpath=\
23 | ${run.test.classpath}
24 | # Files in build.classes.dir which should be excluded from distribution jar
25 | dist.archive.excludes=
26 | # This directory is removed when the project is cleaned:
27 | dist.dir=dist
28 | dist.jar=${dist.dir}/UDPServer.jar
29 | dist.javadoc.dir=${dist.dir}/javadoc
30 | endorsed.classpath=
31 | excludes=
32 | includes=**
33 | jar.compress=false
34 | javac.classpath=
35 | # Space-separated list of extra javac options
36 | javac.compilerargs=
37 | javac.deprecation=false
38 | javac.processorpath=\
39 | ${javac.classpath}
40 | javac.source=1.8
41 | javac.target=1.8
42 | javac.test.classpath=\
43 | ${javac.classpath}:\
44 | ${build.classes.dir}
45 | javac.test.processorpath=\
46 | ${javac.test.classpath}
47 | javadoc.additionalparam=
48 | javadoc.author=false
49 | javadoc.encoding=${source.encoding}
50 | javadoc.noindex=false
51 | javadoc.nonavbar=false
52 | javadoc.notree=false
53 | javadoc.private=false
54 | javadoc.splitindex=true
55 | javadoc.use=true
56 | javadoc.version=false
57 | javadoc.windowtitle=
58 | main.class=udpserver.UDPServer
59 | manifest.file=manifest.mf
60 | meta.inf.dir=${src.dir}/META-INF
61 | mkdist.disabled=false
62 | platform.active=default_platform
63 | run.classpath=\
64 | ${javac.classpath}:\
65 | ${build.classes.dir}
66 | # Space-separated list of JVM arguments used when running the project.
67 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
68 | # To set system properties for unit tests define test-sys-prop.name=value:
69 | run.jvmargs=
70 | run.test.classpath=\
71 | ${javac.test.classpath}:\
72 | ${build.test.classes.dir}
73 | source.encoding=UTF-8
74 | src.dir=src
75 | test.src.dir=test
76 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.java.j2seproject
4 |
5 |
6 | UDPServer
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/udpserver/Request.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 |
3 | /**
4 | *
5 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
6 | * @date 13/Jun/2016
7 | * @project UDP_Server
8 | * @File Request.java
9 | */
10 |
11 | public class Request
12 | {
13 | String via,from,to,callId,cSeq,contact,allow,maxForwards,
14 | userAgent,supported,contentLength;
15 |
16 | public Request() //constructor
17 | {
18 | this.allow = "";
19 | this.cSeq = "";
20 | this.callId = "";
21 | this.contact = "";
22 | this.contentLength = "";
23 | this.from = "";
24 | this.maxForwards = "";
25 | this.supported = "";
26 | this.to = "";
27 | this.userAgent = "";
28 | this.via = "";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/udpserver/UDPServer.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 |
3 | /**
4 | *
5 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
6 | * @date 13/Jun/2016
7 | * @project UDP_Server
8 | * @File UDPServer.java
9 | */
10 |
11 | import java.net.*;
12 | import java.io.*;
13 | import java.util.HashMap;
14 | import java.util.StringTokenizer;
15 |
16 | public class UDPServer
17 | {
18 | private static final int ECHOMAX = 2048; //Stores max length of recieved message in bytes
19 | //HashMap of REGISTERED users
20 | private static HashMap REGISTERED = new HashMap();
21 | //HashMap of Current Calls going on
22 | private static HashMap CURRENTCALLS = new HashMap();
23 |
24 | public static void main(String[] args) throws IOException
25 | {
26 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
27 |
28 | System.out.print("Enter the port of the server (int): ");
29 | int servPort = Integer.parseInt(br.readLine());
30 |
31 | System.out.print("Enter the IP address of the server (String): ");
32 | String servIp = br.readLine();
33 |
34 | System.out.println("Server Started. Listening for requests....");
35 |
36 | //Create new packet to recieve into
37 | DatagramSocket socket = new DatagramSocket(servPort) ;
38 | DatagramPacket packet = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
39 |
40 |
41 | for (;;) //Loops infinitely
42 | {
43 | socket.receive(packet); //Blocks till packet recieved
44 |
45 | InetAddress clientAddress = packet.getAddress(); //client's IP
46 | int clientPort = packet.getPort(); //client's Port
47 |
48 | byte[] arr = new byte[packet.getLength()];
49 | System.arraycopy(packet.getData(), packet.getOffset(), arr, 0, arr.length);
50 | String requestMsg = new String(arr); //recieved Message
51 |
52 |
53 | StringTokenizer st = new StringTokenizer(requestMsg,"\r\n");
54 | String line1 = st.nextToken(); //stores first line of recieved message
55 | String typeOfMsg = line1.substring(0, line1.indexOf(" "));
56 |
57 | if("REGISTER".equals(typeOfMsg)) //If message is of type Register
58 | {
59 | registerRequest r = new registerRequest(); //new register object
60 | String feildName = "";
61 | String nextLine = "";
62 | while(st.hasMoreTokens())
63 | {
64 | nextLine = st.nextToken();
65 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
66 | if("Via".equals(feildName))
67 | r.via = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
68 | else if("From".equals(feildName))
69 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
70 | else if("To".equals(feildName))
71 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
72 | else if("Call-ID".equals(feildName))
73 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
74 | else if("CSeq".equals(feildName))
75 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
76 | else if("Contact".equals(feildName))
77 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
78 | else if("Allow".equals(feildName))
79 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
80 | else if("Max-Forwards".equals(feildName))
81 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
82 | else if("Allow-Events".equals(feildName))
83 | r.allowEvents = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
84 | else if("User-Agent".equals(feildName))
85 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
86 | else if("Supported".equals(feildName))
87 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
88 | else if("Expires".equals(feildName))
89 | r.expires = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
90 | else if("Content-Length".equals(feildName))
91 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
92 | }
93 |
94 | //add to registered the user toRegister
95 | String sipUri = r.contact.substring(r.contact.indexOf(":")+1, r.contact.indexOf(";"));
96 | String number,ipPort;
97 |
98 | if(!sipUri.contains(">"))
99 | {
100 | //this means there is no > (for Jitsi)
101 | number = sipUri.substring(0, sipUri.indexOf("@"));
102 | ipPort = sipUri.substring(sipUri.indexOf("@")+1, sipUri.length());
103 | }
104 | else
105 | {
106 | //this means there is a > (for Phoner)
107 | number = sipUri.substring(0, sipUri.indexOf("@"));
108 | ipPort = sipUri.substring(sipUri.indexOf("@")+1, sipUri.length()-1);
109 | }
110 |
111 | //check if already registered
112 | boolean isRegistered = REGISTERED.containsKey(number);
113 | int expires = Integer.parseInt(r.expires.trim());
114 |
115 | if(!isRegistered && expires > 0) //register
116 | {
117 | System.out.println("Phone "+number+" is Successfully Registered at IP:PORT "+ipPort+" .");
118 | REGISTERED.put(number, ipPort);
119 | }
120 |
121 | else if(isRegistered && expires == 0) //unregister
122 | {
123 | System.out.println("Phone "+number+" is Successfully UNREGISTERED.");
124 | REGISTERED.remove(number);
125 | }
126 |
127 | //send OK response to caller
128 | byte[] send = r.OK_200().getBytes();
129 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
130 | p.setAddress(clientAddress);
131 | p.setPort(clientPort);
132 | p.setData(send);
133 | socket.send(p);
134 |
135 | }
136 |
137 | if("INVITE".equals(typeOfMsg)) //If message is of type Invite
138 | {
139 | inviteRequest r = new inviteRequest(); //new Invite object
140 | String feildName = "";
141 | String nextLine = "";
142 | while(st.hasMoreTokens())
143 | {
144 | nextLine = st.nextToken();
145 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
146 |
147 | if("Via".equals(feildName))
148 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
149 | else if("From".equals(feildName))
150 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
151 | else if("To".equals(feildName))
152 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
153 | else if("Call-ID".equals(feildName))
154 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
155 | else if("CSeq".equals(feildName))
156 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
157 | else if("Contact".equals(feildName))
158 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
159 | else if("Content-Type".equals(feildName))
160 | r.contentType = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
161 | else if("Allow".equals(feildName))
162 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
163 | else if("Max-Forwards".equals(feildName))
164 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
165 | else if("Supported".equals(feildName))
166 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
167 | else if("P-Early-Media".equals(feildName))
168 | r.pEarlyMedia = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
169 | else if("User-Agent".equals(feildName))
170 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
171 | else if("P-Preferred-Identity".equals(feildName))
172 | r.prefferedIdentity = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
173 | else if("Content-Length".equals(feildName))
174 | {
175 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
176 | break;
177 | }
178 | }
179 | while(st.hasMoreTokens()) //Fill data into SDP part of msg
180 | {
181 | nextLine = st.nextToken();
182 | feildName = nextLine.substring(0,nextLine.indexOf("="));
183 | if("v".equals(feildName))
184 | r.v = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
185 | else if("o".equals(feildName))
186 | r.o = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
187 | else if("s".equals(feildName))
188 | r.s = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
189 | else if("c".equals(feildName))
190 | r.c = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
191 | else if("t".equals(feildName))
192 | r.t = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
193 | else if("m".equals(feildName))
194 | r.m = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
195 | else if("a".equals(feildName))
196 | r.a.add(nextLine.substring(nextLine.indexOf("=")+1,nextLine.length()));
197 | }
198 |
199 | //find who is calling
200 | String callerNumber = r.from.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
201 |
202 | //find who to send this invite
203 | String calleeNumber = line1.substring(line1.indexOf(":")+1,line1.indexOf("@"));
204 | String calleeIp = extractIpOrPort(REGISTERED.get(calleeNumber),0);
205 | String calleePort = extractIpOrPort(REGISTERED.get(calleeNumber),1);
206 |
207 | System.out.println("INVITE coming from "+callerNumber+" to " + calleeNumber + " .");
208 |
209 | //send trying back to caller
210 | byte[] send = r.TRYING_100().getBytes();
211 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
212 | p.setAddress(clientAddress);
213 | p.setPort(clientPort);
214 | p.setData(send);
215 | socket.send(p);
216 |
217 | //Now forward this packet to callee
218 | byte[] send1 = r.forwardInvite(line1, servIp, servPort).getBytes();
219 | DatagramPacket p1 = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
220 | p1.setAddress(InetAddress.getByName(calleeIp));
221 | p1.setPort(Integer.parseInt(calleePort.trim()));
222 | p1.setData(send1);
223 | socket.send(p1);
224 |
225 | //add details to CURRENTCALLS
226 | callDetails cd = new callDetails();
227 | cd.caller = callerNumber;
228 | cd.called = calleeNumber;
229 |
230 | String callId = r.callId.substring(0, r.callId.indexOf("@"));
231 | CURRENTCALLS.put(callId, cd);
232 |
233 | }
234 |
235 | if("SIP/2.0 180 Ringing".equals(line1)) //If message is of type Ringing
236 | {
237 | ringingRequest r = new ringingRequest(); //new Ringing Object
238 | String feildName = "";
239 | String nextLine = "";
240 | while(st.hasMoreTokens())
241 | {
242 | nextLine = st.nextToken();
243 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
244 | if("Via".equals(feildName))
245 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
246 | else if("From".equals(feildName))
247 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
248 | else if("To".equals(feildName))
249 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
250 | else if("Call-ID".equals(feildName))
251 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
252 | else if("CSeq".equals(feildName))
253 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
254 | else if("Contact".equals(feildName))
255 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
256 | else if("Allow".equals(feildName))
257 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
258 | else if("Max-Forwards".equals(feildName))
259 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
260 |
261 | else if("User-Agent".equals(feildName))
262 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
263 | else if("Supported".equals(feildName))
264 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
265 |
266 | else if("Content-Length".equals(feildName))
267 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
268 | }
269 |
270 | //extract details of who to forward
271 | String fwdNumber = r.from.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
272 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
273 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
274 |
275 | System.out.println("Ringing forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
276 |
277 | //forward ringing
278 | byte[] send = r.forwardRinging(servIp).getBytes();
279 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
280 | p.setAddress(InetAddress.getByName(fwdIp));
281 | p.setPort(Integer.parseInt(fwdPort.trim()));
282 | p.setData(send);
283 | socket.send(p);
284 | }
285 |
286 | if("SIP/2.0 200 OK".equals(line1)) //If message is of type OK
287 | {
288 | //recieved OK from callee
289 | okRequest r = new okRequest();
290 | String feildName = "";
291 | String nextLine = "";
292 | while(st.hasMoreTokens())
293 | {
294 | nextLine = st.nextToken();
295 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
296 |
297 | if("Via".equals(feildName))
298 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
299 | else if("From".equals(feildName))
300 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
301 | else if("To".equals(feildName))
302 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
303 | else if("Call-ID".equals(feildName))
304 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
305 | else if("CSeq".equals(feildName))
306 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
307 | else if("Contact".equals(feildName))
308 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
309 | else if("Content-Type".equals(feildName))
310 | r.contentType = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
311 | else if("Allow".equals(feildName))
312 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
313 | else if("Max-Forwards".equals(feildName))
314 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
315 | else if("Supported".equals(feildName))
316 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
317 | else if("P-Early-Media".equals(feildName))
318 | r.pEarlyMedia = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
319 | else if("User-Agent".equals(feildName))
320 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
321 | else if("P-Preferred-Identity".equals(feildName))
322 | r.prefferedIdentity = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
323 | else if("Content-Length".equals(feildName))
324 | {
325 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
326 | break;
327 | }
328 | }
329 | while(st.hasMoreTokens())
330 | {
331 | nextLine = st.nextToken();
332 | feildName = nextLine.substring(0,nextLine.indexOf("="));
333 | if("v".equals(feildName))
334 | r.v = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
335 | else if("o".equals(feildName))
336 | r.o = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
337 | else if("s".equals(feildName))
338 | r.s = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
339 | else if("c".equals(feildName))
340 | r.c = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
341 | else if("t".equals(feildName))
342 | r.t = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
343 | else if("m".equals(feildName))
344 | r.m = nextLine.substring(nextLine.indexOf("=")+1,nextLine.length());
345 | else if("a".equals(feildName))
346 | r.a.add(nextLine.substring(nextLine.indexOf("=")+1,nextLine.length()));
347 | }
348 |
349 | //Find out fwd Ok to whom
350 | String fwdNumber = r.from.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
351 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
352 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
353 |
354 | System.out.println("OK forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
355 |
356 | //forward OK
357 | byte[] send = r.forwardOk(servIp).getBytes();
358 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
359 | p.setAddress(InetAddress.getByName(fwdIp));
360 | p.setPort(Integer.parseInt(fwdPort.trim()));
361 | p.setData(send);
362 | socket.send(p);
363 |
364 | }
365 |
366 | if("ACK".equals(typeOfMsg)) //If message is of type ACK
367 | {
368 |
369 | ackRequest r = new ackRequest(); //New ACK object
370 | String feildName = "";
371 | String nextLine = "";
372 | while(st.hasMoreTokens())
373 | {
374 | nextLine = st.nextToken();
375 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
376 | if("Via".equals(feildName))
377 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
378 | else if("From".equals(feildName))
379 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
380 | else if("To".equals(feildName))
381 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
382 | else if("Call-ID".equals(feildName))
383 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
384 | else if("CSeq".equals(feildName))
385 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
386 | else if("Contact".equals(feildName))
387 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
388 | else if("Allow".equals(feildName))
389 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
390 | else if("Max-Forwards".equals(feildName))
391 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
392 |
393 | else if("User-Agent".equals(feildName))
394 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
395 | else if("Supported".equals(feildName))
396 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
397 |
398 | else if("Content-Length".equals(feildName))
399 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
400 | }
401 |
402 | //whom to send this ack
403 | String fwdNumber = r.to.substring(r.to.indexOf(":")+1,r.to.indexOf("@"));
404 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
405 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
406 |
407 | System.out.println("ACK forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
408 |
409 | //forward ack
410 | byte[] send = r.forwardAck(line1, servIp, servPort).getBytes();
411 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
412 | p.setAddress(InetAddress.getByName(fwdIp));
413 | p.setPort(Integer.parseInt(fwdPort.trim()));
414 | p.setData(send);
415 | socket.send(p);
416 | }
417 |
418 | if("BYE".equals(typeOfMsg)) //If message is of type Bye
419 | {
420 | byeRequest r = new byeRequest(); //new Bye object
421 | String feildName = "";
422 | String nextLine = "";
423 | while(st.hasMoreTokens())
424 | {
425 | nextLine = st.nextToken();
426 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
427 | if("Via".equals(feildName))
428 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
429 | else if("From".equals(feildName))
430 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
431 | else if("To".equals(feildName))
432 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
433 | else if("Call-ID".equals(feildName))
434 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
435 | else if("CSeq".equals(feildName))
436 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
437 | else if("Contact".equals(feildName))
438 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
439 | else if("Allow".equals(feildName))
440 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
441 | else if("Max-Forwards".equals(feildName))
442 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
443 |
444 | else if("User-Agent".equals(feildName))
445 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
446 | else if("Supported".equals(feildName))
447 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
448 |
449 | else if("Content-Length".equals(feildName))
450 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
451 | }
452 |
453 | //whom to send this bye
454 | String fwdNumber = r.to.substring(r.to.indexOf(":")+1,r.to.indexOf("@"));
455 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
456 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
457 |
458 | System.out.println("BYE forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
459 |
460 | //Forward BYE
461 | byte[] send = r.forwardBye(line1, servIp, servPort).getBytes();
462 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
463 | p.setAddress(InetAddress.getByName(fwdIp));
464 | p.setPort(Integer.parseInt(fwdPort.trim()));
465 | p.setData(send);
466 | socket.send(p);
467 |
468 | //remove this call from CURRENTCALLS
469 | String callId = r.callId.substring(0, r.callId.indexOf("@"));
470 |
471 | if(CURRENTCALLS.containsKey(callId))
472 | {
473 | System.out.println("The call from "+CURRENTCALLS.get(callId).caller+" to "+CURRENTCALLS.get(callId).called+" has been ENDED.");
474 | CURRENTCALLS.remove(callId);
475 | }
476 | }
477 |
478 | if("CANCEL".equals(typeOfMsg)) //If message is of type Cancel
479 | {
480 | cancelRequest r = new cancelRequest(); //new Cancel object
481 | String feildName = "";
482 | String nextLine = "";
483 | while(st.hasMoreTokens())
484 | {
485 | nextLine = st.nextToken();
486 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
487 | if("Via".equals(feildName))
488 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
489 | else if("From".equals(feildName))
490 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
491 | else if("To".equals(feildName))
492 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
493 | else if("Call-ID".equals(feildName))
494 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
495 | else if("CSeq".equals(feildName))
496 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
497 | else if("Contact".equals(feildName))
498 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
499 | else if("Allow".equals(feildName))
500 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
501 | else if("Max-Forwards".equals(feildName))
502 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
503 |
504 | else if("User-Agent".equals(feildName))
505 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
506 | else if("Supported".equals(feildName))
507 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
508 |
509 | else if("Content-Length".equals(feildName))
510 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
511 | }
512 |
513 | //Find forward cancel to whom
514 | String fwdNumber = r.to.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
515 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
516 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
517 |
518 | System.out.println("Cancel forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
519 |
520 | //forward cancel
521 | byte[] send = r.forwardCancel(line1,servIp,servPort).getBytes();
522 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
523 | p.setAddress(InetAddress.getByName(fwdIp));
524 | p.setPort(Integer.parseInt(fwdPort.trim()));
525 | p.setData(send);
526 | socket.send(p);
527 |
528 | //remove callDetails
529 | String callId = r.callId.substring(0,r.callId.indexOf("@"));
530 | if(CURRENTCALLS.containsKey(callId))
531 | CURRENTCALLS.remove(callId);
532 | }
533 |
534 | if(line1.contains("487 Request")) //If message is of type 487
535 | {
536 | requestTerminatedRequest r = new requestTerminatedRequest();
537 | String feildName = "";
538 | String nextLine = "";
539 | while(st.hasMoreTokens())
540 | {
541 | nextLine = st.nextToken();
542 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
543 | if("Via".equals(feildName))
544 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
545 | else if("From".equals(feildName))
546 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
547 | else if("To".equals(feildName))
548 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
549 | else if("Call-ID".equals(feildName))
550 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
551 | else if("CSeq".equals(feildName))
552 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
553 | else if("Contact".equals(feildName))
554 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
555 | else if("Allow".equals(feildName))
556 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
557 | else if("Max-Forwards".equals(feildName))
558 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
559 |
560 | else if("User-Agent".equals(feildName))
561 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
562 | else if("Supported".equals(feildName))
563 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
564 |
565 | else if("Content-Length".equals(feildName))
566 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
567 | }
568 |
569 | //forward to whom
570 | String fwdNumber = r.from.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
571 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
572 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
573 |
574 | System.out.println("Request Terminated forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
575 |
576 | //forward 487
577 | byte[] send = r.forwardrequestTerminated(line1,servIp,servPort).getBytes();
578 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
579 | p.setAddress(InetAddress.getByName(fwdIp));
580 | p.setPort(Integer.parseInt(fwdPort.trim()));
581 | p.setData(send);
582 | socket.send(p);
583 | }
584 |
585 | if(line1.contains("486 Busy")) //If message is of type Busy
586 | {
587 | requestTerminatedRequest r = new requestTerminatedRequest();
588 | String feildName = "";
589 | String nextLine = "";
590 | while(st.hasMoreTokens())
591 | {
592 | nextLine = st.nextToken();
593 | feildName = nextLine.substring(0,nextLine.indexOf(":"));
594 | if("Via".equals(feildName))
595 | r.via.add(nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length()));
596 | else if("From".equals(feildName))
597 | r.from = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
598 | else if("To".equals(feildName))
599 | r.to = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
600 | else if("Call-ID".equals(feildName))
601 | r.callId = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
602 | else if("CSeq".equals(feildName))
603 | r.cSeq = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
604 | else if("Contact".equals(feildName))
605 | r.contact = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
606 | else if("Allow".equals(feildName))
607 | r.allow = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
608 | else if("Max-Forwards".equals(feildName))
609 | r.maxForwards = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
610 |
611 | else if("User-Agent".equals(feildName))
612 | r.userAgent = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
613 | else if("Supported".equals(feildName))
614 | r.supported = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
615 |
616 | else if("Content-Length".equals(feildName))
617 | r.contentLength = nextLine.substring(nextLine.indexOf(" ")+1,nextLine.length());
618 | }
619 |
620 | //forward to whom
621 | String fwdNumber = r.from.substring(r.from.indexOf(":")+1, r.from.indexOf("@"));
622 | String fwdIp = extractIpOrPort(REGISTERED.get(fwdNumber),0);
623 | String fwdPort = extractIpOrPort(REGISTERED.get(fwdNumber),1);
624 |
625 | System.out.println("Busy Here forwarded to "+fwdNumber+" at IP:PORT "+fwdIp+":"+fwdPort+" .");
626 |
627 | //forward 486
628 | byte[] send = r.forwardrequestTerminated(line1,servIp,servPort).getBytes();
629 | DatagramPacket p = new DatagramPacket(new byte[ECHOMAX], ECHOMAX);
630 | p.setAddress(InetAddress.getByName(fwdIp));
631 | p.setPort(Integer.parseInt(fwdPort.trim()));
632 | p.setData(send);
633 | socket.send(p);
634 |
635 | //remove from CURRENTCALLS
636 | String callId = r.callId.substring(0,r.callId.indexOf("@"));
637 | if(CURRENTCALLS.containsKey(callId))
638 | CURRENTCALLS.remove(callId);
639 | }
640 |
641 |
642 | packet.setLength(ECHOMAX);
643 |
644 | }
645 |
646 | }
647 |
648 |
649 | private static String extractIpOrPort(String s,int choice) //Returns IP or PORT from SIP URI
650 | {
651 | if(choice == 0) //returns IP if choice == 0
652 | {
653 | return s.substring(0, s.indexOf(":"));
654 | }
655 | else //else returns PORT
656 | return s.substring(s.indexOf(":")+1);
657 | }
658 | }
--------------------------------------------------------------------------------
/src/udpserver/ackRequest.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 | /**
3 | *
4 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
5 | * @date 13/Jun/2016
6 | * @project UDP_Server
7 | * @File ackRequest.java
8 | */
9 | import java.util.ArrayList;
10 |
11 |
12 | public class ackRequest extends Request
13 | {
14 | ArrayList via; //List of via headers
15 |
16 | ackRequest() //constructor
17 | {
18 | super();
19 | via = new ArrayList<>();
20 | }
21 |
22 | public String forwardAck(String line1,String servIp,int servPort)
23 | {
24 | String fwd_res = line1 + "\r\n";
25 |
26 | //add recieved to topmost via feild
27 | String upperViaFeild = via.get(0);
28 | String recieved = upperViaFeild.substring(upperViaFeild.indexOf(" ")+1, upperViaFeild.indexOf(":"));
29 | upperViaFeild = upperViaFeild + ";recieved=" + recieved;
30 | via.set(0, upperViaFeild);
31 |
32 | //add this server's Via tag
33 | via.add(0,"SIP/2.0/UDP "+servIp+":"+servPort+";branch=z9hG4bK2d4790");
34 |
35 | //add via feilds
36 | for(int in=0;in via;
15 | byeRequest()
16 | {
17 | super();
18 | via = new ArrayList<>();
19 | }
20 |
21 | public String forwardBye(String line1,String servIp,int servPort)
22 | {
23 | String fwd_res = line1 + "\r\n";
24 |
25 | //add recieved to topmost via feild
26 | String upperViaFeild = via.get(0);
27 | String recieved = upperViaFeild.substring(upperViaFeild.indexOf(" ")+1, upperViaFeild.indexOf(":"));
28 | upperViaFeild = upperViaFeild + ";recieved=" + recieved;
29 | via.set(0, upperViaFeild);
30 |
31 | //add this server's Via tag
32 | via.add(0,"SIP/2.0/UDP "+servIp+":"+servPort+";branch=z9hG4bK2d4790");
33 |
34 | for(int in=0;in";
44 | fwd_res = fwd_res + "Contact: " + modifiedContact + "\r\n";
45 |
46 | fwd_res = fwd_res + "Max-Forwards: " + (Integer.parseInt(maxForwards.trim())-1) + "\r\n";
47 | fwd_res = fwd_res + "User-Agent: " + userAgent + "\r\n";
48 | fwd_res = fwd_res + "Content-Length: " + contentLength + "\r\n\r\n";
49 | return fwd_res;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/udpserver/callDetails.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 |
3 | /**
4 | *
5 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
6 | * @date 13/Jun/2016
7 | * @project UDP_Server
8 | * @File callDetails.java
9 | */
10 | public class callDetails
11 | {
12 | String caller; //Stores caller Phone number
13 | String called; //Stores the Called Phone number
14 |
15 |
16 | callDetails() //constructor
17 | {
18 | caller = "";
19 | called = "";
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/udpserver/cancelRequest.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | *
7 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
8 | * @date 13/Jun/2016
9 | * @project UDP_Server
10 | * @File cancelRequest.java
11 | */
12 | public class cancelRequest extends Request
13 | {
14 | ArrayList via;
15 | cancelRequest()
16 | {
17 | super();
18 | via = new ArrayList<>();
19 | }
20 | public String forwardCancel(String line1,String servIp,int servPort)
21 | {
22 | String fwd_res = line1 + "\r\n";
23 |
24 | //add recieved to topmost via feild
25 | String upperViaFeild = via.get(0);
26 | String recieved = upperViaFeild.substring(upperViaFeild.indexOf(" ")+1, upperViaFeild.indexOf(":"));
27 | upperViaFeild = upperViaFeild + ";recieved=" + recieved;
28 | via.set(0, upperViaFeild);
29 |
30 | //add this server's Via tag
31 | via.add(0,"SIP/2.0/UDP "+servIp+":"+servPort+";branch=z9hG4bK2d4790");
32 |
33 | //add via feilds
34 | for(int in=0;in a,via;
17 |
18 | public inviteRequest()
19 | {
20 | super();
21 | this.contentType = "";
22 | this.pEarlyMedia = "";
23 | this.prefferedIdentity = "";
24 |
25 | this.v = "";
26 | this.c = "";
27 | this.m = "";
28 | this.o = "";
29 | this.s = "";
30 | this.t = "";
31 |
32 | a = new ArrayList<>();
33 | via = new ArrayList<>();
34 | }
35 | public String TRYING_100() //method to generate trying response
36 | {
37 | String trying_res = "SIP/2.0 100 TRYING\r\n";
38 |
39 | //add recieved to topmost via feild
40 | String upperViaFeild = via.get(0);
41 | String recieved = upperViaFeild.substring(upperViaFeild.indexOf(" ")+1, upperViaFeild.indexOf(":"));
42 | upperViaFeild = upperViaFeild + ";recieved=" + recieved;
43 | via.set(0, upperViaFeild);
44 |
45 | for(int in=0;in";
77 | fwd_res = fwd_res + "Contact: " + modifiedContact + "\r\n";
78 |
79 | fwd_res = fwd_res + "Content-Type: " + contentType + "\r\n";
80 | fwd_res = fwd_res + "Max-Forwards: " + (Integer.parseInt(maxForwards.trim())-1) + "\r\n";
81 | fwd_res = fwd_res + "User-Agent: " + userAgent + "\r\n";
82 | fwd_res = fwd_res + "Content-Length: " + contentLength + "\r\n\r\n";
83 |
84 | fwd_res = fwd_res + "v=" + v + "\r\n";
85 | fwd_res = fwd_res + "o=" + o + "\r\n";
86 | fwd_res = fwd_res + "s=" + s + "\r\n";
87 | fwd_res = fwd_res + "c=" + c + "\r\n";
88 | fwd_res = fwd_res + "t=" + t + "\r\n";
89 | fwd_res = fwd_res + "m=" + m + "\r\n";
90 |
91 | for(int in=0;in";
42 | fwd_res = fwd_res + "Contact: " + modifiedContact + "\r\n";
43 | }
44 |
45 | fwd_res = fwd_res + "Content-Length: " + contentLength + "\r\n\r\n";
46 |
47 | if(!cSeq.contains("BYE") && !cSeq.contains("CANCEL")) /*If this OK is not in response to a
48 | BYE or a CANCEL then
49 | */
50 | {
51 | fwd_res = fwd_res + "v=" + v + "\r\n";
52 | fwd_res = fwd_res + "o=" + o + "\r\n";
53 | fwd_res = fwd_res + "s=" + s + "\r\n";
54 | fwd_res = fwd_res + "c=" + c + "\r\n";
55 | fwd_res = fwd_res + "t=" + t + "\r\n";
56 | fwd_res = fwd_res + "m=" + m + "\r\n";
57 |
58 | for(int in=0;in via;
15 | requestTerminatedRequest()
16 | {
17 | super();
18 | via = new ArrayList<>();
19 | }
20 | public String forwardrequestTerminated(String line1,String servIp,int servPort)
21 | {
22 | String fwd_res = line1 + "\r\n";
23 |
24 | if(via.get(0).contains(","))
25 | {
26 | String modifiedVia = via.get(0).substring(via.get(0).indexOf(",")+1,via.get(0).length());
27 | via.set(0,modifiedVia);
28 | }
29 | else
30 | via.remove(0);
31 |
32 |
33 | //add via feilds
34 | for(int in=0;in";
43 | fwd_res = fwd_res + "Contact: " + modifiedContact + "\r\n";
44 |
45 | fwd_res = fwd_res + "User-Agent: " + userAgent + "\r\n";
46 |
47 | fwd_res = fwd_res + "Content-Length: 0" + "\r\n\r\n";
48 |
49 | return fwd_res;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/udpserver/ringingRequest.java:
--------------------------------------------------------------------------------
1 | package udpserver;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | *
7 | * @author Rajat Saxena & Shivam Dabral & Biwas Bisht
8 | * @date 13/Jun/2016
9 | * @project UDP_Server
10 | * @File ringingRequest.java
11 | */
12 | public class ringingRequest extends Request
13 | {
14 | ArrayList via;
15 | ringingRequest()
16 | {
17 | super();
18 | via = new ArrayList<>();
19 | }
20 | public String forwardRinging(String servIp)
21 | {
22 | String fwd_res = "SIP/2.0 180 Ringing\r\n";
23 |
24 | String modifiedVia = via.get(0).substring(via.get(0).indexOf(",")+1,via.get(0).length());
25 | via.set(0,modifiedVia);
26 |
27 | //add via feilds
28 | for(int in=0;in";
37 | fwd_res = fwd_res + "Contact: " + modifiedContact + "\r\n";
38 |
39 | fwd_res = fwd_res + "User-Agent: " + userAgent + "\r\n";
40 |
41 | fwd_res = fwd_res + "Content-Length: 0" + "\r\n\r\n";
42 |
43 | return fwd_res;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------