Client Example

7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.97
List Price:  €134.36
You save:  €38.39
£79.78
List Price:  £111.69
You save:  £31.91
CA$144.01
List Price:  CA$201.62
You save:  CA$57.61
A$160.98
List Price:  A$225.38
You save:  A$64.40
S$135.95
List Price:  S$190.34
You save:  S$54.38
HK$776.08
List Price:  HK$1,086.54
You save:  HK$310.46
CHF 90.05
List Price:  CHF 126.07
You save:  CHF 36.02
NOK kr1,135.75
List Price:  NOK kr1,590.10
You save:  NOK kr454.34
DKK kr715.78
List Price:  DKK kr1,002.12
You save:  DKK kr286.34
NZ$177.65
List Price:  NZ$248.72
You save:  NZ$71.06
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,929.84
List Price:  ৳16,702.26
You save:  ৳4,772.41
₹8,553.87
List Price:  ₹11,975.77
You save:  ₹3,421.89
RM447.10
List Price:  RM625.96
You save:  RM178.86
₦154,684.53
List Price:  ₦216,564.53
You save:  ₦61,880
₨27,792.76
List Price:  ₨38,910.97
You save:  ₨11,118.21
฿3,397.46
List Price:  ฿4,756.58
You save:  ฿1,359.12
₺3,523.69
List Price:  ₺4,933.31
You save:  ₺1,409.61
B$617.89
List Price:  B$865.08
You save:  B$247.18
R1,874.30
List Price:  R2,624.10
You save:  R749.79
Лв187.76
List Price:  Лв262.88
You save:  Лв75.11
₩147,469.07
List Price:  ₩206,462.60
You save:  ₩58,993.52
₪367.60
List Price:  ₪514.66
You save:  ₪147.05
₱5,818.31
List Price:  ₱8,145.87
You save:  ₱2,327.56
¥15,774.33
List Price:  ¥22,084.69
You save:  ¥6,310.36
MX$2,029.11
List Price:  MX$2,840.83
You save:  MX$811.72
QR363.08
List Price:  QR508.32
You save:  QR145.24
P1,386.50
List Price:  P1,941.15
You save:  P554.65
KSh12,948.70
List Price:  KSh18,128.70
You save:  KSh5,180
E£5,087.27
List Price:  E£7,122.38
You save:  E£2,035.11
ብር12,710.92
List Price:  ብር17,795.80
You save:  ብር5,084.87
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$99,027.09
List Price:  CLP$138,641.89
You save:  CLP$39,614.80
CN¥729.84
List Price:  CN¥1,021.81
You save:  CN¥291.96
RD$6,081.12
List Price:  RD$8,513.82
You save:  RD$2,432.69
DA13,556.89
List Price:  DA18,980.19
You save:  DA5,423.30
FJ$232.21
List Price:  FJ$325.11
You save:  FJ$92.89
Q768.97
List Price:  Q1,076.59
You save:  Q307.62
GY$20,886.35
List Price:  GY$29,241.72
You save:  GY$8,355.37
ISK kr13,925.60
List Price:  ISK kr19,496.40
You save:  ISK kr5,570.80
DH1,006.73
List Price:  DH1,409.47
You save:  DH402.73
L1,843.82
List Price:  L2,581.42
You save:  L737.60
ден5,907.37
List Price:  ден8,270.56
You save:  ден2,363.18
MOP$798.63
List Price:  MOP$1,118.11
You save:  MOP$319.48
N$1,856.28
List Price:  N$2,598.86
You save:  N$742.58
C$3,673.45
List Price:  C$5,142.98
You save:  C$1,469.52
रु13,596.38
List Price:  रु19,035.48
You save:  रु5,439.09
S/371.74
List Price:  S/520.45
You save:  S/148.71
K405.18
List Price:  K567.27
You save:  K162.09
SAR375.49
List Price:  SAR525.70
You save:  SAR150.21
ZK2,762.82
List Price:  ZK3,868.06
You save:  ZK1,105.23
L477.59
List Price:  L668.64
You save:  L191.05
Kč2,415.86
List Price:  Kč3,382.31
You save:  Kč966.44
Ft39,457.05
List Price:  Ft55,241.45
You save:  Ft15,784.40
SEK kr1,100.32
List Price:  SEK kr1,540.49
You save:  SEK kr440.17
ARS$102,865.20
List Price:  ARS$144,015.40
You save:  ARS$41,150.19
Bs689.84
List Price:  Bs965.80
You save:  Bs275.96
COP$440,915.37
List Price:  COP$617,299.16
You save:  COP$176,383.78
₡50,688.88
List Price:  ₡70,966.47
You save:  ₡20,277.58
L2,536.46
List Price:  L3,551.14
You save:  L1,014.68
₲778,577.57
List Price:  ₲1,090,039.75
You save:  ₲311,462.17
$U4,443.67
List Price:  $U6,221.32
You save:  $U1,777.64
zł410.31
List Price:  zł574.45
You save:  zł164.14
Already have an account? Log In

Transcript

Hello, in this Java programming video, we are going to take a look at networking. This particular tutorial, we're going to create a client file. And then in the next video which you know, this, you know, two parter section in this series will create the server. And at the end of the next video, we'll run it all together. So I'm going to set up the client that's going to connect to our server. So the thing I'm going to do is rename the class to client.

Save that that will give an error, hover over it and click Rename file. So this rename this forwards Yeah, and the reason is you need to make sure that the Java file or the actual class file or the you know executable that's created afterwards is the same name as your class and this will ensure that and the third one will do the same. Where did they come in next video. We need a couple of inputs so import java, a Java Java dotnet dot Asterix Okay, so now in here, first thing first is going to create is going to do, I'm going to create something called the server name. And this we're going to get from the arguments. So these are the command line arguments, the separate video covering them, feel free to check them out.

And this in Amelie is going to, you know, specify the name of the server. So the localhost in our case. Now we need to create a variable, and this will basically get the argument, which will be the second argument that was fine, there'll be a port number. This will give us an error because this is not an integer, so we will need to parse it by doing integer dot parse int like so. And now we're going to do a Troy And we'll go well, the catch is going to be recorded accordingly. Okay, and in here moaning about them.

Moo coo. Okay, yeah, we haven't implemented so yeah fun. In here, we will just do x dot points that will just print the stack trace. In case of any problems in here, we are going to first just print out, you know everything that we're connecting to. So it's going to assist them. dot dot print ln.

And we're going to say next. And it's going to the server name, server name We're going to pick the port now. Okay, that's pretty cool. Now we are going to create a client using the socket class socket client socket in here with the server name and the port. So this will allow us to actually create the connection and very soon and now we'll print out the actual connection so it's just connected to them to get remote socket address, so this is going to print out what is actually connected Now we're going to get an input and this will equal the point here now we're going to create the data output stream data equals new data stream and we specify you know the output stream that we just created the long before. Now we are going to do data dot write UTF eight you know printf to the console, no white something about, you know, hello from the actual client.

So on the server we can get information but we could pass in, there are some coordinates to a player for example, if we're creating our next awesome fortnight game, from the say hello from Wiley Get local copy to dress. Where are we connecting from because it could be multiple connection potentially input stream. And, in understand in equals client input string like so. And it's going to do a data input stream that data input. And I'm going to call this input equals new data inputs through input and the system, dot print line. And this really, you know, whatever the Service says.

So this is what we'll get So, before we do in the read you like so and now we're gonna close the class and close. That's it. We're gonna mess it up, made put in here. There we go. That's it, save it, no errors and go to your bin folder. So once you compile it or once you save it, eclipse will compile it.

If you're not using a kit, make sure you have compiled the file. Don't ever want to hear. So grab hold of that and go to the desktop. paste it here. And we'll be rolling this in the next video. So thanks for watching.

In the next tutorial, we're going to be covering creating the server file. And I look forward to seeing you in that puzzle tutorial.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.