-
Notifications
You must be signed in to change notification settings - Fork 1
/
sen.java
52 lines (47 loc) · 1.49 KB
/
sen.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
51
52
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class sen
{
String addr=JOptionPane.showInputDialog("Enter address: ");
String name="";
public sen()
{
try
{
JFrame jp=new JFrame();
FileDialog fd=new FileDialog(jp,"select the file",FileDialog.LOAD);
fd.show();
if(fd.getFile()!=null)
{
name=fd.getDirectory()+fd.getFile();
}//if
System.out.println("Ip addr" + fd.getFile());
File f1=new File(name);
if(f1.exists())
{
FileInputStream fis=new FileInputStream(f1);
byte[] b=new byte[fis.available()];
//Socket sc=new Socket(addr,2222);
Socket sc=new Socket("192.168.0.3",2222);
OutputStream os=sc.getOutputStream();
for(int i=0;i<b.length;i++)
{
b[i]=(byte)fis.read();
}
ByteArrayOutputStream bout= new ByteArrayOutputStream();
bout.write(b,0,b.length);
bout.writeTo(os);
JOptionPane.showMessageDialog(null,"Message sent successfully","Message",JOptionPane.INFORMATION_MESSAGE);
}//if
else
JOptionPane.showMessageDialog(null,"File not found","Message",JOptionPane.INFORMATION_MESSAGE);
}catch(UnknownHostException ex){
JOptionPane.showMessageDialog(null,"Host not found","Message",JOptionPane.INFORMATION_MESSAGE);}
catch(IOException iex){
JOptionPane.showMessageDialog(null,"Unable to perform IO","Message",JOptionPane.INFORMATION_MESSAGE);
}
}
}//class