-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVoIPClient.java
More file actions
123 lines (85 loc) · 2.82 KB
/
Copy pathVoIPClient.java
File metadata and controls
123 lines (85 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
/*
* VoIPClient.java
*
* Version:
* 1.0
*
* Revisions:
* 0
*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.sound.sampled.AudioFormat;
/**
* Class used to create the instance of the client side of the VoIP
* application.
*
* @author Siddharth Kalluru
* @author Vijaykumar Chandrashekar
*/
public class VoIPClient{
public Socket objSock; //Socket to establish connection with server
public DatagramSocket objDGSock; //Socket to stream the voice
//Server Details
public InetAddress ipAddrOfServer;
public int portOfServer;
public int streamPort;
//I/O parameters
public BufferedInputStream objBIS;
public BufferedOutputStream objBOS;
AudioFormat objAudioFormat;
/**
* Constructor to initialize the instance of VoIPClient
*
* @param ipOfServer IP address of Server
*
* @param portOfServer Port of Server to be used for chat and
* exchange of control messages
*
* @param streamPort Port to be used for streaming of voice
*/
public VoIPClient(String ipOfServer, int portOfServer,
int streamPort) throws UnknownHostException, IOException{
this.ipAddrOfServer = InetAddress.getByName(ipOfServer);
this.portOfServer = portOfServer;
this.streamPort = streamPort;
//Create client socket to connect server
objSock = new Socket(ipOfServer, portOfServer);
//Bind the client to the stream port to receive and stream voice
objDGSock = new DatagramSocket(streamPort);
//Get the channels to send data
objBIS = new BufferedInputStream(objSock.getInputStream());
objBOS = new BufferedOutputStream(objSock.getOutputStream());
}
/**
* The main program.
*
* @param args IPaddress of Server and Port of Server
*/
public static void main(String [] args){
if(args.length == 2){
String ipOfServer = args[0];
int portOfServer = Integer.parseInt(args[1]);
int streamPort = portOfServer+1;
try{
//Create the client and connect to the server
VoIPClient objClient = new VoIPClient(ipOfServer, portOfServer, streamPort);
HostUI clientUI = new HostUI("Client", objClient.objSock, objClient.objDGSock,
objClient.ipAddrOfServer, streamPort);
//Draw the UI
clientUI.drawUI("Connected to host.\n");
}catch(Exception e){
System.out.println(" Couldn't connect to host with IP address: "+ipOfServer +
" and port :" + portOfServer );
}
}
else
System.out.println("Usage: Please run the client side application as follows\n"+
"java VoIPClient <ip address of server> <port of server>");
}
}