Java で書かれたクライアント/サーバー プログラム (ソケットを使用する) があります。接続を確立する複数の機能があります。例えば:
public static void some_sender(byte[] x0, byte[] x1) //he is a server
{
ServerSocket s=new ServerSocket(8888);
s.setSoTimeout(10000);
Socket incoming=s.accept();
ObjectOutputStream oos = new ObjectOutputStream(incoming.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(incoming.getInputStream());
//some sending and receiving
some_sender0(a);
}
public static void some_sender0(int a)
{
ServerSocket s=new ServerSocket(8888);
s.setSoTimeout(10000);
Socket incoming=s.accept();
ObjectOutputStream oos = new ObjectOutputStream(incoming.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(incoming.getInputStream());
//some sending and receiving
}
私が client() で持っているのと同じこと
public static byte[] some_receiver(byte b)
{
Socket s=new Socket("127.0.0.1", 8888);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios=new ObjectInputStream(s.getInputStream());
//some sending and receiving
byte[] t=some_receiver0(c);
return m;
}
public static byte[] some_receiver0(byte c)
{
Socket s=new Socket("127.0.0.1", 8888);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios=new ObjectInputStream(s.getInputStream());
//some sending and receiving
return y;
}
私の質問は実行方法です(サーバーの初期化)
ServerSocket s=new ServerSocket(8888);
s.setSoTimeout(10000);
Socket incoming=s.accept();
ObjectOutputStream oos = new ObjectOutputStream(incoming.getOutputStream());
ObjectInputStream ios = new ObjectInputStream(incoming.getInputStream());
と(クライアント)
Socket s=new Socket("127.0.0.1", 8888);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ios=new ObjectInputStream(s.getInputStream());
ネストされたすべての関数で使用します。
前もって感謝します。