我想说 = = 你是不是 判断语句的结果 写反了??? 成功写成失败结果,失败写成成功结果?
还有,如果你使用了路由, 不使用穿透技术, 服务端 和 客户端 这两个组件就是玩具,没有什么用的 = =。
对,就是要用端口映射。
第一个参数的话要填你电脑的外网ip(查外网ip:在百度搜索输入 ip ,按回车就可也看到了)。
第二个参数是填你映射的那个端口,还有服务端的端口应该和你映射的端口一致才可以!
虚拟服务器定义了广域网服务端口和局域网网络服务器之间的映射关系,所有对该广域网服务端口的访问将会被重定位给通过IP地址指定的局域网网络服务器。
这段话的意思是 所有访问你外网IP指定端口的连接都转到你的电脑上 [指定端口=服务端口号]
通俗点 比如 你客户1连接的IP端口是1
那么在服务端口号填1 IP地址就填你本地连接的IP地址(不可以自动获取IP地址,要给它一个固定的)
协议选择ALL
最后那个常用不用选 别管他
可以考虑用JAVA实现监听客户端口,参考例子如下:
package test;import javaioByteArrayOutputStream;
import javaioIOException;
import javaioInputStream;
import javaioOutputStream;
import javalangreflectMethod;
import javanetDatagramPacket;
import javanetDatagramSocket;
import javanetInetAddress;
import javanetServerSocket;
import javanetSocket;
import javanetSocketException;
import javautilHashMap;
import javautilLinkedList;
import javautilList;
import javautilRandom;
/
该程序用的DatagramSocket,实现UDP的通讯
@author D'Addario
/
public class Test{
private int headLen = 12;//消息起点和终点的记录 例如classAclassB就是发往classA的消息,发送者是classB
private Random random;
private String serverIp;
private int serverPort;
private HashMap<String,Classes> map ;
{
serverIp = "127001";
serverPort = 9999;
random = new Random(SystemcurrentTimeMillis());
map = new HashMap<String,Classes>();
Classes A = Testthisnew Classes();
Aip = "127001";
Aname = "我是A";
Aport = 10000;
mapput("classA", A);
Classes B = Testthisnew Classes();
Bip = "127001";
Bname = "我是B";
Bport = 10001;
mapput("classB", B);
}
public static void main(String[] a) throws Exception{
Test test = new Test();
new Thread(testnew Server())start();
Client client1 = testnew Client();
client1mine = "classA";
client1remote = "classB";
new Thread(client1)start();
Client client2 = testnew Client();
client2mine = "classB";
client2remote = "classA";
new Thread(client2)start();
}
/
成员 用于记录 每个成员的个性信息
@author D'Addario
/
private class Classes {
private String name ; //成员姓名
private String ip ; //成员ip
private int port;//成员的client server 监听端口
}
/
server 用于转发两个client之间消息的类
@author D'Addario
/
private class Server implements Runnable{
public void run() {
// TODO Auto-generated method stub
boolean start = false;
DatagramSocket socket = null;
try {
socket = new DatagramSocket(serverPort);
start = true;
} catch (SocketException e1) {
e1printStackTrace();
}
while(start)
{
try {
byte[] data = new byte[1024];
DatagramPacket packet = new DatagramPacket(data,datalength);
socketreceive(packet);
int len = packetgetLength();
//Systemoutprintln("recevie data:"+new String(data,0,len));
if(len<headLen)
throw new IOException("无效数据");
String id = new String(data,0,headLen/2);//获取发往对象的ID
String id2 = new String(data,headLen/2,headLen/2);
Systemoutprintln("receive from "+id2 +", send to "+id+",msg["+new String(data,headLen,len-headLen)+"]");
Classes one = mapget(idtrim());
DatagramPacket retPack = new DatagramPacket(data,0,len,InetAddressgetByName(oneip),oneport);
socketsend(retPack);
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
}
}
/
Client 客户端类,用于客户端消息的发送
@author D'Addario
/
private class Client implements Runnable{
private String mine;
private String remote;
public void run() {
// TODO Auto-generated method stub
String msg = remote+mine;
DatagramSocket socket = null;
try {
socket = new DatagramSocket(mapget(mine)port);
ClientServer srv=new ClientServer();
srvsetSocket(socket);
new Thread(srv)start();
} catch (SocketException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
byte[] data ;
while(true)
{
String sendStr = msg + "给我"+randomnextInt(5000)+"分吧";
data = sendStrgetBytes();
try {
DatagramPacket retPack = new DatagramPacket(data,0,datalength,InetAddressgetByName(serverIp),serverPort);
socketsend(retPack);
Threadsleep(randomnextInt(5)1000);
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
}
}
/
客户端server 用于监听服务器的消息
@author D'Addario
/
private class ClientServer implements Runnable{
DatagramSocket socket ;
public DatagramSocket getSocket() {
return socket;
}
public void setSocket(DatagramSocket socket) {
thissocket = socket;
}
public void run() {
byte[] data = new byte[1024];
DatagramPacket packet = new DatagramPacket(data,datalength);
while(true){
try {
socketreceive(packet);
int len = packetgetLength();
if(len<headLen)
throw new IOException("无效数据");
Systemoutprintln("I get the message :"+ThreadcurrentThread()getId()+"-->["+new String(data,0,len)+"]");
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} }
}
}
}
以上就是关于易语言远程控制端口连接测试全部的内容,包括:易语言远程控制端口连接测试、易语言关于服务器与客户端以及端口映射、易语言服务器映射端口后客户端怎么连接服务器等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)