clearguy Posted November 13, 2006 Share Posted November 13, 2006 (edited) HI, I have tryed to chat with a friend with a tcp server and 2 clients: SERVER expandcollapse popup#include <guiconstants.au3> TCPStartup() Dim Const $MAX_CONNECTIONS = 100 Dim $link[$MAX_CONNECTIONS] $vvv=0 While $vvv<$MAX_CONNECTIONS; all arays are set to -1 $link[$vvv]=-1 $vvv=$vvv+1 WEnd $main=TCPListen(@IPAddress1,9999); Creates a socket on your PC and 'listen' to any connection Dim $GOOEY = GUICreate("My Server (IP: " & @IPAddress1 & ")",350,200) Dim $edit = GUICtrlCreateEdit("",10,10,320,180) GUISetState() While 1; main loop $i=0 While $i<$MAX_CONNECTIONS; Selects the first aray which is set to -1, to use it If $link[$i]=-1 Then $link[$i]=TCPAccept($main) ExitLoop EndIf $i=$i+1 WEnd $msg=GUIGetMsg() If $msg=$GUI_EVENT_CLOSE Then Exit $j=0 While $j<$MAX_CONNECTIONS; loop that search in the arays an active connection If $link[$j]<>-1 Then; if a connection is active $recv=TCPRecv($link[$j],10000) if $recv<>"" Then Dim $szIP_Accepted = SocketToIP($link[$j]); Get IP of client connecting If $recv<>'DISCO' Then GUICtrlSetData($edit, _ $szIP_Accepted &' Socket:'&$link[$j]& ' Client:'&$j&' > ' & $recv & @CRLF & GUICtrlRead($edit)); set data in edit ;TCPSend($link[$j],$recv) Else GUICtrlSetData($edit, _ $szIP_Accepted &' Socket:'&$link[$j]& ' Client:'&$j&' is disconnected !' & @CRLF & GUICtrlRead($edit)) $link[$j]=-1 TCPCloseSocket ( $link[$j] ) EndIf $ddd=0 While $ddd<$MAX_CONNECTIONS If $link[$ddd]<>-1 Then TCPSend($link[$ddd],$recv); information is sent back to the connected socket?? EndIf $ddd=$ddd+1 WEnd EndIf EndIf $j=$j+1 WEnd WEnd Func SocketToIP($SHOCKET) Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]") Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _ "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFuncoÝ÷ Ø Ý±êïz»"uè§ÂhÙ²~¸Ûh¦ëfÊ*ZÛaz+·ß}õ!TDZºÚ"µÍÚ[ÛYH ÑÝZPÛÛÝ[Ë]LÉÝÂÚ[ÛYH ÑÝZQY]]LÉÝÂÚ[ÛYH ÓZØË]LÉÝÂØØ[ ÌÍÔÙR[]Þ ][ÝÔÙ][ÝË ][ÝÔXÙH[]HÙ[ÝHÛÝ[ZÙHÈÛÛXÝÎ][ÝÊBØØ[ ÌÍÔÜR[]Þ ][ÝÔÙÜ ][ÝË ][ÝÔXÙH[]HÜÜHÙ[ÝHÛÝ[ZÙHÈÛÛXÝÎ][ÝÊBÔÝ BÌÍÓXZ[ÛØÚÙ]HÔÛÛXÝ ÌÍÔÙ ÌÍÔÜ BY ÌÍÓXZ[ÛØÚÙ]HLH[^]ÙÐÞ ][ÝÑÜ][ÝË ][ÝÐÛÝ[ÝÛÛXÝÜYÛÛXÝ[Û][ÝÊBÕRPÜX]J ][ÝÔÙÛY[ ][ÝËÎLL BÌÍÔÙ[HÕRPÝÜX]QY] ][ÝÉ][ÝËLLMÍKML ÌÍÕÔ×ÕÐÔÓ BØØ[ ÌÍÒÝÜHHÕRPÝÜX]QY] ][ÝÓXZ[ÙYÜØYÙÎ][ÝËLMÍKML]Ô ÌÍÕÔ×ÕÐÔÓ ÌÍÑT×ÔPQÓJJBÌÍÔÐ]ÛHÕRPÝÜX]P]Û ][ÝÔÙ[ ][ÝËM KMKLÍJBÕRTÙ]Ý]J BÚ[HBIÌÍÛÙÈHÕRQÙ]ÙÊ BRY ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑH[BUÔÙ[ ÌÍÓXZ[ÛØÚÙ] ÌÎNÑTÐÓÉÌÎNÈ BBQ^]Q[ÙRY ÌÍÛÙÈH ÌÍÔÐ]ÛÜÒÔÜÙY ][ÝÌ ][ÝÊHHH[BIÌÍÕ^HÕRPÝXY ÌÍÔÙ[ BBIÌÍÕÔÙ[HÔÙ[ ÌÍÓXZ[ÛØÚÙ] ÌÍÕ^ BBQÕRPÝÙ]]J ÌÍÔÙ[ ][ÝÉ][ÝÊBQ[YIÌÍÔXÝHÔXÝ ÌÍÓXZ[ÛØÚÙ] LLBRY ÌÍÔXÝ ÉÝÈ ][ÝÉ][ÝÈ[BQÕRPÝÙ]]J ÌÍÒÝÜKÕRPÝXY ÌÍÒÝÜJH [ÈÔ [È ÌÍÔXÝBBWÑÕRPÝY][TØÜÛ ÌÍÒÝÜKÑÕRPÝY]Ù][PÛÝ[ ÌÍÒÝÜJJBQ[YÑ[[ÈÛ]]Ò]^] BUÔÛÜÙTÛØÚÙ] ÌÍÓXZ[ÛØÚÙ] BUÔÚ]ÝÛ B[[ÎÏOIÝÓÛ]]Ò]^] Myself I can connect , and many clients at the same time, but chating with myself gets annoying . And no problem with my firewall, maybe because my friend is behind a router... but he tells me that all ports are open !!!!! EDIT: my friend is behind a router* Edited November 13, 2006 by clearguy I've never met anyone who codes binary. StringMultiInsert()SOW EncryptFrench autoit forum - forum français Link to comment Share on other sites More sharing options...
clearguy Posted November 13, 2006 Author Share Posted November 13, 2006 (edited) describe your internet connection.... I internet connect all the time... so the problem is your configuration with the internet... something you are not considering.Lar.My connection :8Mb, dynamic IP adress.. and I'm conecting by every start up, I get a new IP adress (value returned by @IPAdress2)The value returned by @IPAdress1, which is used by the server and client, is every time the same.Maybe it is that the problem, I will try to use @IPAdress2 for the server, my dynamic ip, and for the client to.Thanx !EDIT: yes now it's perfect, big thanx to Larry:) Edited November 13, 2006 by clearguy I've never met anyone who codes binary. StringMultiInsert()SOW EncryptFrench autoit forum - forum français Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now