473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[SOLVED] socket issue, should be easy to fix

1
edit: nevermind fixed it by re-opening the sockets whenever this one specific error string is detected

this is my first time using winsock in years and am having some trouble. pretty sure all it needs is a simple line of code for closing a socket or something similar..i've just killed too many hours trying different things, so i figured i'll just ask the experts for once and hopefully nip it in the bud

i'm building off a very basic open source proxy server (it supports keep-alive and ssl), i'm making it so it bypasses sony PS3 firmware...i actually managed to get that to work though.

it's weird actually, everything works fine so it seems, in ps3 i can switch users and log in/out without a problem..but the problem occurs only when i restart my ps3, it ceases to log me in and the only way i can get it working again is if i restart the proxy server program.


here's the working log:
---server started---
client accepted on socket 1
socket 1: recieve state:0
out socket connected to fus01.ps3.update.playstation.net on 1
out socket 1: send
here's the not working log:

client accepted on socket 1
socket 1: recieve state:0
ssl connection made on out-socket: 1 to auth.np.ac.playstation.net
socket 1: recieve state:1
out socket 1: send
socket 1: recieve state:1
out socket 1: send
socket 1: recieve state:1
out socket 1: send
socket 1: recieve state:1
out socket 1: send
socket 1: recieve state:1
out socket 1: send
clean up on 1 from: buck_dataarrival(2805 bytes sent) host: auth.np.ac.playstation.net
client accepted on socket 1
socket 1: recieve state:0
out socket connected to mercury.dl.playstation.net on 1
out socket 1: send
clean up on 1 from: buck_error: Connection is aborted due to timeout or other failure (err. no. 10053)(0 bytes sent) host: mercury.dl.playstation.net
and here's the barebones of the code:
Expand|Select|Wrap|Line Numbers
  1. Private curRequest(20)
  2. Private curHost(20)
  3. Private connType(20)
  4. Private lenSent&(20)
  5. Private curLength(20)
  6. Private curResp(20)
  7. Private sslDone(20) As Boolean
  8.  
  9. Public gstrAccessLevel As String
  10.  
  11.  
  12. Public Sub cleanup(aIndex As Integer, from As String)
  13. buck(aIndex).Close
  14.  
  15. curRequest(aIndex) = ""
  16. curResp(Index) = ""
  17. curHost(aIndex) = ""
  18. sslDone(aIndex) = False
  19. chuck(aIndex).Tag = 0
  20. buck(aIndex).Tag = 0
  21. lenSent(aIndex) = 0
  22. curLength(aIndex) = ""
  23. End Sub
  24.  
  25. Private Sub chuck_ConnectionRequest(Index As Integer, ByVal requestID As Long)
  26.  
  27. For i = 1 To 20
  28.     If chuck(i).State = sckClosing Then chuck(i).Close
  29.     If chuck(i).State = sckClosed Then
  30.         chuck(i).Accept requestID
  31.         accepted = True
  32.         Exit Sub
  33.     End If
  34. Next
  35.  
  36. End Sub
  37.  
  38. Private Sub chuck_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  39. On Error Resume Next
  40. Dim strdata$
  41. chuck(Index).GetData strdata
  42.  
  43. Select Case chuck(Index).Tag
  44. Case 1
  45.  
  46.     If buck(Index).State = sckConnected Then
  47.         buck(Index).SendData strdata
  48.     ElseIf buck(Index).State = sckClosed Then
  49.         buck(Index).Connect curHost(Index)
  50.         curRequest(Index) = curRequest(Index) & strdata$
  51.     Else
  52.         If InStr(1, curRequest(Index), vbCrLf & vbCrLf) > 0 Then
  53.             chuck(Index).Tag = 0
  54.         Else
  55.             curRequest(Index) = curRequest(Index) & strdata$
  56.         End If
  57.     End If
  58. Case 0
  59.  
  60.         If Left(strdata, 8) = "CONNECT " Then
  61.  
  62.             colon = InStr(1, strdata, ":")
  63.             curHost(Index) = Mid(strdata, 9, colon - 9)
  64.             SSLPORT = Mid(strdata, colon + 1, InStr(colon, strdata, " ") - colon)
  65.             begin = InStr(1, LCase(strdata), "proxy-connection: ")
  66.  
  67.             If begin <> 0 Then
  68.                 connType(Index) = Mid(strdata, begin + 18, InStr(begin, strdata, vbCrLf) - begin - 18)
  69.                 If LCase(connType(Index)) = "keep-alive" Then curRequest(Index) = Replace(strdata, Mid(strdata, begin, InStr(begin, strdata, ":") - begin), "connection") ': MsgBox curRequest(Index)
  70.             End If
  71.  
  72.             curRequest(Index) = Right(strdata, Len(strdata) - InStr(1, strdata, vbCrLf & vbCrLf) - 3)
  73.             If buck(Index).State <> sckClosed Then buck(Index).Close: DoEvents
  74.             buck(Index).Connect curHost(Index), Trim(SSLPORT)
  75.             buck(Index).Tag = 4
  76.             chuck(Index).Tag = 1
  77.             Exit Sub
  78.         End If
  79.     yea = Replace(strdata, "http://", "", , 1)
  80.     begin = InStr(1, yea, " ")
  81.  
  82.     If begin <> 0 Then shit = Mid(yea, begin + 1, InStr(begin, yea, "/") - begin - 1)
  83.     If (curHost(Index) <> shit And buck(Index).State <> sckClosed) Then buck(Index).Close
  84.     curHost(Index) = shit
  85.  
  86.     yea = Replace(yea, shit, "", 1, 1)
  87.     curRequest(Index) = yea
  88.     chuck(Index).Tag = 1
  89.     begin = InStr(1, LCase(yea), "proxy-connection: ")
  90.  
  91.     If begin <> 0 Then
  92.         connType(Index) = Mid(yea, begin + 18, InStr(begin, yea, vbCrLf) - begin - 18)
  93.         If LCase(connType(Index)) = "keep-alive" Then curRequest(Index) = Replace(yea, Mid(yea, begin, InStr(begin, yea, ":") - begin), "connection")
  94.     End If
  95.     buck(Index).Tag = 1
  96.     lenSent(Index) = 0
  97.     If LCase(connType(Index)) = "keep-alive" Then
  98.         buck(Index).Tag = 0
  99.         If buck(Index).State = sckConnected Then
  100.  
  101.             curResp(Index) = ""
  102.  
  103.             buck(Index).SendData curRequest(Index)
  104.             Exit Sub
  105.         End If
  106.     End If
  107.     If buck(Index).State <> sckClosed Then buck(Index).Close: DoEvents
  108.     buck(Index).Connect curHost(Index)
  109. End Select
  110. strdata$ = ""
  111. End Sub
  112.  
  113. Private Sub chuck_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  114.  
  115. chuck(Index).Close
  116. cleanup (Index), "chuck_error: " & Description
  117. End Sub
  118.  
  119. Private Sub chuck_SendComplete(Index As Integer)
  120. If curLength(Index) = lenSent(Index) Then
  121. If connType(Index) <> "keep-alive" Then
  122. chuck(Index).Close
  123. Call cleanup(Index, "all data relayed")
  124. End If
  125. End If
  126.  
  127. If buck(Index).Tag <> 4 Then
  128.     buck(Index).Tag = 0
  129. Else
  130.     sslDone(Index) = True
  131. End If
  132. If chuck(Index).Tag = 3 Then
  133.     cleanup (Index), "chuck_sendcomplete"
  134.     chuck(Index).Close
  135.     DoEvents
  136. End If
  137.  
  138. End Sub
  139.  
  140. Private Sub buck_Close(Index As Integer)
  141. Debug.Print "out socket close on " & Index
  142. If buck(Index).Tag <> 0 Then
  143.     If sslDone(Index) = False Then
  144.         chuck(Index).Tag = 3
  145.         Exit Sub
  146.     End If
  147. Else
  148.     cleanup (Index), "buck_close"
  149.     chuck(Index).Close
  150. End If
  151.  
  152. cleanup (Index), "buck_close"
  153. chuck(Index).Close
  154. If buck(Index).Tag = 4 Then
  155.     If sslDone(Index) = True Then
  156.         chuck(Index).Close
  157.         cleanup Index, "buck_close ssl style"
  158.     End If
  159. End If
  160.  
  161. End Sub
  162.  
  163. Private Sub buck_Connect(Index As Integer)
  164.  
  165. If buck(Index).Tag = "4" Then
  166.     chuck(Index).SendData "HTTP/1.1 200 Connection established" & vbCrLf _
  167.     & "Proxy-agent: PS3Update-agent/1.0.0 libhttp/1.0.0" & vbCrLf & vbCrLf
  168. End If
  169. If curRequest(Index) <> "" Then
  170.     buck(Index).SendData curRequest(Index)
  171. End If
  172. If buck(Index).Tag <> 4 Then buck(Index).Tag = 0
  173. End Sub
  174.  
  175. Private Sub buck_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  176. Dim strdatas$
  177. buck(Index).GetData strdatas$
  178.  
  179.             If Len(strdatas$) < 275 Then
  180.             workspace.Text = strdatas$
  181.             On Error Resume Next
  182.         If Left(workspace, 2) = "# " Then
  183.             Dim str As Variant
  184.             Dim fixit As String
  185.  
  186.             str = Split(workspace, ";CompatibleSystemSoftwareVersion=")
  187.             fixit = Left(str(1), 6)
  188.             str(1) = Replace(str(1), fixit, "0.0000")
  189.             workspace = str(0) & ";CompatibleSystemSoftwareVersion=" & str(1)
  190.  
  191.             str = Split(workspace, ";SystemSoftwareVersion=")
  192.             fixit = Left(str(1), 6)
  193.             str(1) = Replace(str(1), fixit, "0.0000")
  194.             workspace = str(0) & ";SystemSoftwareVersion=" & str(1)
  195.  
  196.             str = Split(workspace, ";ImageVersion=")
  197.             fixit = Left(str(1), 8)
  198.             str(1) = Replace(str(1), fixit, "00000000")
  199.             workspace = str(0) & ";ImageVersion=" & str(1)
  200.             strdatas$ = workspace.Text
  201.         End If
  202. End If
  203.  
  204. If curResp(Index) = "" Then
  205.     begin = InStr(1, LCase(strdatas$), "content-length:") + 15
  206.     If begin > 15 Then curLength(Index) = Trim(Mid(strdatas$, begin, InStr(begin, strdatas$, vbCrLf) - begin))
  207.     Debug.Print strdatas$
  208.     curResp(Index) = Left(strdatas$, InStr(1, strdatas$, vbCrLf & vbCrLf) - 1)
  209. If curResp(Index) <> "" Then recvHead = True
  210. End If
  211.  
  212. If buck(Index).Tag <> 4 Then chuck(Index).Tag = 0
  213. If buck(Index).Tag = 0 Then buck(Index).Tag = 1
  214. sslDone(Index) = False
  215. If curLength(Index) = "" Then RECVDHEAD = False
  216. If RECVDHEAD = True Then
  217.     lenSent(Index) = Len(strdatas$) - Len(curResp(Index))
  218.  
  219. Else
  220.     lenSent(Index) = lenSent(Index) + Len(strdatas$)
  221. End If
  222. If chuck(Index).State = sckConnected Then
  223.     chuck(Index).SendData strdatas$
  224.     DoEvents
  225. Else
  226.     cleanup (Index), "buck_dataarrival"
  227.     Exit Sub
  228. End If
  229.  
  230. End Sub
  231.  
  232. Private Sub buck_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  233. cleanup (Index), "buck_error: " & Description & " (err. no. " & Number & ")"
  234. chuck(Index).Close
  235.  
  236. End Sub
  237.  
  238. Private Sub Form_Load()
  239. Dim strCommandLine As String
  240. strCommandLine = UCase(Command())
  241.  If InStr(strCommandLine, "-PORT ") > 0 Then
  242.  Dim setport As Variant
  243.  setport = Split(strCommandLine, "-PORT ")
  244.  Text2.Text = setport(1)
  245.  End If
  246.  
  247.     For i = 1 To 20
  248.     Load chuck(i)
  249.     Load buck(i)
  250.     Next
  251.     chuck(0).LocalPort = Text2.Text
  252.     chuck(0).Listen
  253. End Sub
  254.  
any help is appreciated, sorry if this thread isn't put together that well, tried to explain it as best as i could
Apr 13 '10 #1
0 1093

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Nathan Davis | last post by:
Hi, I am having problems reading data from a socket. The problem only occurs while trying to read from one particular server, and does not occur on Windows (as far as I know, this may occur...
8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
5
by: Russell Warren | last post by:
Does anyone know the scope of the socket.setdefaulttimeout call? Is it a cross-process/system setting or does it stay local in the application in which it is called? I've been testing this and...
2
by: Barry C.Hawkins | last post by:
List, Hello. I am trying to get PostgreSQL 7.3.4 installed after moving to Mac OS 10.3, known as Panther. I am using the following configure statement: pbg417:/usr/local/src/postgresql-7.3.4...
6
by: Astroman | last post by:
Hi guys and girls. This is my first time posting here so go easy :) . I was wondering if someone could please interpret how this csum() function works in the following C code. I know that the...
4
by: Alexander Muylaert | last post by:
Hi I their a way I can interupt socket.Receive. I want my multi-threader server to be able to handle requests as wel as Broadcast messages. This broadcasting is done when the socket is not...
5
by: kuba bogaczewicz | last post by:
Hello all, for my school project I have to write a small peer-2-peer application using Sockets, and I've chosen C# for the task. I've been doing some research on the topic, and I would really...
8
by: Claire | last post by:
I'm trying to debug my network application ie I want to check my error handling when the connection is broken. Im using 127.0.0.1 as the connection address. Unfortunately, the client socket goes...
8
by: Mark Fink | last post by:
I try to port a server application to Jython. At the moment I use Jython21\Lib\socket.py Currently I do face problems with casting the string "localhost" to the desired value:...
10
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.