-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocketDataR.java
50 lines (44 loc) · 1.07 KB
/
socketDataR.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatbox2;
/**
*
* @author Gagan
*/
import java.io.IOException;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class socketDataR implements Runnable{
Thread t;
int myPort;
boolean working;
chatBoxFrame cBF;
DatagramSocket ds;
byte buffer[];
int buffer_size=1024;
public socketDataR(int p,chatBoxFrame cbf,DatagramSocket dS) {
myPort=p;
cBF=cbf;
ds=dS;
t=new Thread(this);
working=true;
buffer=new byte[buffer_size];
t.start();
}
@Override
public void run() {
DatagramPacket dp=new DatagramPacket(buffer,buffer_size);
while(working)
{
try {
ds.receive(dp);
} catch (IOException ex) {
}
cBF.addText((new String(dp.getData(),0,dp.getLength())));
}
}
}