调用时也要抛出或捕获异常!
import java.io.*;
import java.net.*;
public class Server
{
public Server()
{
}
public void Test() throws IOException
{
ServerSocket s = new ServerSocket(8080);
try
{
Socket socket1 = s.accept();
try
{
}
finally
{
socket1.close();
}
}
finally
{
s.close();
}
}
public static void main(String args[])
throws IOException{
Server test = new Server();
test.Test(); }}
import java.io.*;
import java.net.*;
public class Server
{
public Server()
{
}
public void Test() throws IOException
{
ServerSocket s = new ServerSocket(8080);
try
{
Socket socket1 = s.accept();
try
{
}
finally
{
socket1.close();
}
}
finally
{
s.close();
}
}
public static void main(String args[])
throws IOException{
Server test = new Server();
test.Test(); }}
关键怎么调用main函数?
我现在做的是windows应用程序
要响应按钮消息
class BlinstenListner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Server test = new Server();
test.Test();
}
}
帮忙啊!~~~
catch(IOException ioe){...}
class BlinstenListner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Server test = new Server();
try
{
test.Test();
}
catch(IOExcetpion e)
{
}
}
}
分数我会在别的帖子里给
(汗……20分太少了)
我还有几个问题,希望能得到解答
1。我现在是用jcreator写程序,怎么单步执行?你们都是用什么软件啊??
2。还是上面的程序,连接上后有什么反应??调用的是哪个函数?accept()吗?是不是要重载?
3。有没有你们自己做的小程序借我看看?(有界面的)
连接上了有什么反应是什么意思?你重载accept()要实现什么功能?
你要看什么?
accept()后要接受消息的话可加上
ServerSocket s = new ServerSocket(8080);
Socket socket=s.accept()
InputStream s=socket.getInputStream();
OutputStream os=socket.getOutputStream();
DIn=new DataInputStream(is);
Din.readLine();客户端要socket=new Socket("127.0.0.1",8080);
os=new socket.getOutputStream();
ps=new PrintStream(os);
DataInputStream userin=new DataInputStream(System.in);
str=Userin.readLine();
ps.println(str);
str=
不好意思,这么晚才结贴。。