hi... I using this code for a chat program....
Is there a way to use only one Winsock to send and recive data??
I also want that when someone request a connection, both sides conects....

VB Code:
  1. ''''''''''Server code
  2. Dim intMax As Integer
  3.  
  4. Private Sub Command2_Click()
  5.     Winsock2.SendData "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»>  " & Text1.Text
  6.     List1.AddItem "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»>  " & Text1.Text
  7.     Text1.Text = ""
  8.     Text1.SetFocus
  9. End Sub
  10.  
  11.  
  12. Private Sub Form_Load()
  13.     Me.Winsock1(0).LocalPort = GetSetting(App.EXEName, "Options", "Port", "6668")
  14.     Winsock1(0).Listen
  15.     List1.AddItem "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»>  " & Text1.Text
  16.  
  17. End Sub
  18.  
  19.  
  20. Private Sub Text1_KeyPress(KeyAscii As Integer)
  21. If KeyAscii = vbKeyReturn Then
  22.     Command2_Click
  23. End If
  24. End Sub
  25.  
  26. Private Sub Winsock1_Close(Index As Integer)
  27.     Winsock1(Index).SendData "Conexão Fechada para:" & Winsock1(Index).RemoteHostIP & "  Em: " & Now
  28.     Winsock1(Index).Close
  29.     List1.AddItem "Conexão Fechada para:" & Winsock1(Index).RemoteHostIP & "  Em: " & Now
  30. End Sub
  31.  
  32.  
  33. Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
  34.     If Index = 0 Then
  35.         intMax = intMax + 1
  36.         Load Winsock1(intMax)
  37.         Winsock1(intMax).LocalPort = 0
  38.         Winsock1(intMax).Accept requestID
  39.         List1.AddItem "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & "  Em: " & Now
  40.     End If
  41. End Sub
  42.  
  43. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  44. Dim strIncoming As String, Result As String
  45. Dim sString As String, MyArray() As String
  46.  
  47.     Winsock1(Index).GetData strIncoming
  48.  
  49.     List1.AddItem strIncoming
  50.  
  51.     Winsock1(Index).SendData Result
  52.    
  53. End Sub
  54.  
  55. '''''Client Code
  56. Private Sub Command1_Click()
  57.  
  58. If Winsock2.State <> sckClosed Then Winsock2.Close
  59.  
  60.     Winsock2.RemotePort = Combo1.Text
  61.     Winsock2.RemoteHost = Combo2.Text
  62.  
  63.     Winsock2.Connect
  64.  
  65. ' Try and Connect to the Server
  66. Do Until Winsock2.State = sckConnected
  67.     DoEvents: DoEvents: DoEvents: DoEvents
  68.     If Winsock2.State = sckError Then
  69.         MsgBox "There was a problem connecting to the Server!" & vbCrLf & "Please try again later!", vbOKOnly, "Connection Error"
  70.         Exit Sub
  71.     End If
  72. Loop
  73.  
  74. Winsock2.SendData Now & " »»> " & Text1.Text
  75. Command2.Enabled = True
  76. Text1.Enabled = True
  77. Command1.Enabled = False
  78.  
  79. End Sub
  80.  
  81.  
  82.  
  83. Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long)
  84.         intMax = intMax + 1
  85.      
  86.         Winsock1(intMax).LocalPort = 0
  87.         Winsock1(intMax).Accept requestID
  88.         List1.AddItem "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & "  Em: " & Now
  89.         Winsock2.SendData "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & "  Em: " & Now
  90.  
  91.     Winsock2.RemotePort = Combo1.Text
  92.     Winsock2.RemoteHost = Winsock1(Index).RemoteHostIP
  93.  
  94.     Winsock2.Connect
  95.  
  96. ' Try and Connect to the Server
  97. Do Until Winsock2.State = sckConnected
  98.     DoEvents: DoEvents: DoEvents: DoEvents
  99.     If Winsock2.State = sckError Then
  100.         MsgBox "There was a problem connecting to the Server!" & vbCrLf & "Please try again later!", vbOKOnly, "Connection Error"
  101.         Exit Sub
  102.     End If
  103. Loop
  104.  
  105. Winsock2.SendData Now & " »»> " & Text1.Text
  106. Command2.Enabled = True
  107. Text1.Enabled = True
  108. Command1.Enabled = False
  109.  
  110.  
  111.  
  112.  
  113. End Sub
  114.  
  115. Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
  116. Dim strReply As String
  117.  
  118.     Winsock2.GetData (strReply)
  119.    
  120.         MsgBox strReply
  121.  
  122. End Sub


thanks in advance