aboutsummaryrefslogtreecommitdiff
path: root/CS2452/GUI_network/SocketWriter.java
blob: 1d882ab38c280309f2dd944833c0e503190323bb (plain)
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
package assign6;

import java.io.*;
import java.net.*;
import java.util.concurrent.Semaphore;

public class SocketWriter extends Thread
{
	Thread t;
	BufferedWriter bw;
	Semaphore write;
	boolean sc;
	
	public SocketWriter(Socket s, Semaphore write)
	{
		try{
		this.bw  = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
		
		this.write = write;
		
			

		t = new Thread(this);
		t.start();
	}
	
	public void run()
	{
	
		while(true)
		{
			try
			{
				write.acquire();
			} catch (InterruptedException e1)
			{
				e1.printStackTrace();
			}
			try
			{
				bw.newLine();
				bw.flush();
			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
				
	}

}