-
Notifications
You must be signed in to change notification settings - Fork 1
/
server1.java
40 lines (35 loc) · 931 Bytes
/
server1.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
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class server1
{
public static void main(String a[])
{
String jo=JOptionPane.showInputDialog("Enter File Name"+" *(must be .jpeg , .jpg or .bmp extension)");
System.out.println(jo);
if(jo==null)
{
System.exit(0);
}
int j=0,i=0;
byte[] b=new byte[10000000] ;
try{
ServerSocket ss =new ServerSocket(2222);
Socket sc =ss.accept();
InputStream is=sc.getInputStream();
System.out.println("after accept");
FileOutputStream fos=new FileOutputStream(jo);
j=is.read();
while(j!=-1)
{
fos.write(j);
j=is.read();
}
fos.close();
is.close();
JOptionPane.showMessageDialog(null,"Message recieved successfully","Message",JOptionPane.INFORMATION_MESSAGE);
System.out.println("End of Writing into file");
}catch(Exception e){e.printStackTrace();}
}
}