This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 我有一个有关SOCKET的问题请各位搞通信的兄弟赐教:如果在一个IP上有两个CLIENT和同一SERVER通信,这两个CLIENT的IP和TCP PORT都一样,会不会出现接受到SERVER数据混乱的情况?为什么?
-guest:;
2001-7-28
(#148555@0)
-
是否混乱取决于你编程了,因为两个client的IP和TCP port 都一样,所以一定要有一个不同的变量可以用于区分两个client, 这实际上等于你发的TCP包里又多了一层子包,意思就说到这儿了,挺乱的,你不明白我也没办法
-000(老九);
2001-7-28
(#148557@0)
-
C的SOCKET我没试过,JAVA我没有做任何编程上的考虑,不会混乱。为什么?
-guest:;
2001-7-28
(#148563@0)
-
很简单,你的TCP的data里留一个字节用来区分两个client不就行了吗
-000(老九);
2001-7-28
(#148568@0)
-
我是说在JAVA编程里我没有做任何的改动也没有问题,奇怪是吧?
-guest:;
2001-7-28
(#148571@0)
-
Java我不熟,但感觉应该是两个client都收到了同样的包(包括应发往另一个client的包),是否是因为你程序里各自期待的数据不同自然过滤掉了?
-000(老九);
2001-7-28
(#148591@0)
-
我是说你的数据包里
-000(老九);
2001-7-28
(#148569@0)
-
九兄这几天都在忙什么呀
-slimpiggy(瘦猪犹如插翅虎);
2001-7-28
(#148575@0)
-
The server end should be Multi-Thread program
-shou(小受);
2001-7-29
(#148778@0)
-
你试过吗?
-guest:;
2001-7-29
(#148784@0)
-
我是说JAVA 的SERVER SIDE的SOCKET可以是单线程的
-guest:;
2001-7-29
(#148810@0)
-
I wrote HTTP, FTP, SMTP, POP, Socks 4/5, Proxy server before
-shou(小受);
2001-7-29
(#148816@0)
-
那怎么区别不同CLIENT 的呢?
-guest:;
2001-7-29
(#148817@0)
-
Are you the guest asked for help? The sever end creats thread for each client, thats it
-shou(小受);
2001-7-29
(#148819@0)
-
是但SERVER的THREAD怎么知道自己连的是哪一个CLIENT呢?处了IP,PORT还要用老九说的办法吗?如果不用似乎没有别的措施呀?
-guest:;
2001-7-29
(#148821@0)
-
不同的会话当然不会乱了!发包方有地址,接收方也有地址呀!不是发给它的包它不会理的 ...
-maladuona(马拉多纳);
2001-7-29
(#148789@0)
-
你说的SESSION 是指什么,能不能具体一点?
-guest:;
2001-7-29
(#148800@0)
-
我是指client端发起一个请求,服务器会返回一个带地址的响应(非常具体的地址,指明为其服务的具体实体[可能是个线程,也可能是独立的进程]),这样一个会话是不会乱的,明白吗? ...
-maladuona(马拉多纳);
2001-7-29
(#148803@0)
-
服务器端的进程或线程之间是绝对不会混的,java应该是由VM自动管理多线程,所以你不用编程实现(我这么理解)...
-maladuona(马拉多纳);
2001-7-29
(#148805@0)
-
你说的是JAVA吗?你如何知道:一个带地址的响应?
-guest:;
2001-7-29
(#148806@0)
-
我怎么觉得这种情况不会发生. 当一个client bind到一个port上之后, 如果另一个client想bind到相同的port, kernel就会给出错误信息, 说该port已经被占用, 无法bind.TCP/IP是在kernel里面的, 至少在unix上是这样. Or am I missing something?
-dennis2(Dennis);
2001-7-29
{70}
(#148823@0)
-
至少我试过JAVA的MULTI-THREAD的SOCKET,可以这样做的,没有问题。
-guest:;
2001-7-29
(#148825@0)
-
更有趣的是所有的SERVER的THREAD和CLIENT都在同一台机上用同样的IP和PORT!!!
-guest:;
2001-7-29
(#148826@0)
-
CLIENT/SERVER只用一对IP,PORT(如127。0。0。1:7070),由PROGRAMMER定义不一定要WELL KNOW PORT。
-guest:;
2001-7-29
(#148830@0)
-
子线程会继承父进程的资源,如FILE,SOCKET descriptor。
-huofu(huofu);
2001-7-29
(#148827@0)
-
FILE 和DESCRIPTOR应该有东西能鉴别对方(CLIENT)的DESCRIPTOR
-guest:;
2001-7-29
(#148829@0)
-
That's how server works. But my understanding of what he is saying is that 2 independent client process can use the same TCP port, which I don't think possible.
-dennis2(Dennis);
2001-7-29
(#148832@0)
-
你都无法解释哪怕只有一个CLIENT,CLIENT和SERVER THREAD用同一IO/PORT的情况!
-guest:;
2001-7-29
(#148836@0)
-
SORRY 是CLIENT 和SERVER 在同一机上用同一 IP/PORT。
-guest:;
2001-7-29
(#148838@0)
-
That is not possible. How did you know they are using the same IP/port? Post your result of "netstat -a -n -f inet" please. Also, which OS are you using?
-dennis2(Dennis);
2001-7-29
(#148841@0)
-
一个JAVA SOCKET程序,我可以自己定义CLIENT/SERVER的IP/PORT 同时运行多个CLIENT和一个SERVER。
-guest:;
2001-7-29
(#148843@0)
-
You can define in your program doesn't mean you can run it. Please post your result of "netstat -a -n". I will believe you until I see it.
-dennis2(Dennis);
2001-7-29
(#148845@0)
-
看来是遇到高人了请进,(我是用127。0。0。1和7771)CONSTRUCT的SOCKET(包括C/S)TCP 0.0.0.0:7771 0.0.0.0:0 LISTENING
TCP 0.0.0.0:3796 0.0.0.0:0 LISTENING
TCP 127.0.0.1:7771 127.0.0.1:3796 ESTABLISHED
TCP 127.0.0.1:3737 127.0.0.1:7771 TIME_WAIT
TCP 127.0.0.1:3738 127.0.0.1:7771 TIME_WAIT
TCP 127.0.0.1:3739 0.0.0.0:0 LISTENING
TCP 127.0.0.1:3796 127.0.0.1:7771 ESTABLISHED
UDP 127.0.0.1:3739 *:*
-guest:;
2001-7-29
{487}
(#148848@0)
-
进一步报告
-guest:;
2001-7-29
{671}
(#148855@0)
-
well...it's quite normal...On a port, there can be mutiple in-bound connection while there can be only one out-bound connection...
-pazu(InTheSky);
2001-8-2
(#153878@0)
-
I'm no Gao Ren, in fact, I'm a freshman, a stubborn one. :-) Anyway, I have to go to sleep now. Nice chatting with you guys.
-dennis2(Dennis);
2001-7-29
(#148856@0)
-
等一等,还是有问题,见上贴
-guest:;
2001-7-29
(#148857@0)
-
OK, those entries with ESTABLISHED keyword indicate established connections. In those entries, c/s ports cannot be the same, which is indicated in your result.
-dennis2(Dennis);
2001-7-29
(#148858@0)
-
client 不用PORT bind() ;
-huofu(huofu);
2001-7-29
(#148850@0)
-
But client has to use a port, right?
-dennis2(Dennis);
2001-7-29
(#148851@0)
-
used for find the correct server process. the port = a server process
-huofu(huofu);
2001-7-29
(#148852@0)
-
From unix-socket-faq:It has been pointed out that "A socket is a 5 tuple (proto, local addr, local port, remote addr, remote port). SO_REUSEADDR just says that you can reuse local addresses. The 5 tuple still must be unique!"
-dennis2(Dennis);
2001-7-29
{211}
(#148853@0)
-
呵呵,port只对SERVER端process而言,client端PROCESS 建立SOCKET后,不用BIND(),用WELL KNOWN PORT 建立CONNECTION 就可以READ()AND WRITE()了
-huofu(huofu);
2001-7-29
(#148849@0)
-
agree with u
-trafford(老特,上火中...);
2001-8-2
(#153272@0)
-
无论是JAVA还是C的SOCKET编程,SERVER端都是以不变应万变,即在WELL KNOWN PORT ACCEPT 来自任何CLIENT端的CONNECTION请求,随即在子线程中用新分配的唯一新SOCKET与唯一对应的CLIENT通信,这是个原则,需要编程实现
-huofu(huofu);
2001-7-29
(#148824@0)
-
不会!这仅仅是一个端口复用的技术......
-xxjjs(东方射日);
2001-7-29
{912}
(#148859@0)
-
我的妈呀,这么简单的问题还有这么多讨论.
-bugkiller(bugkiller);
2001-8-2
(#153269@0)
-
after I saw all the response I know how u guys can't find a good job. so stupid.
the socket address is composed of (serverIP,server Port,client Ip,Client Port), so how could u got a mess?
-frankwoo(frank);
2001-8-22
(#176480@0)
-
No problem.whenever the server reveive a request, it will throw a new thread or process to handle it.
eg, you can ping a server from one station N times.
-mcdonald(麦当劳);
2001-8-22
{145}
(#176492@0)
-
不会搞混的!怎么搞得这么复杂?想象在同一台client上FTP或Telnet到同一台server上的情况就行了。嘿嘿。
-guest:随便说说;
2001-8-24
(#178754@0)