9bb Subj : Proxy Service Issues To : All From : Drakmir Date : Fri Oct 07 2005 10:56:00 Re: Proxy Service Issues By: Drakmir to All on Thu Oct 06 2005 08:44 am So, after working on it last night and with some hints from Digital Man, I've come up with something that seems to work to proxy a socket. There is only one unknown, and I've noticed that the use of "sendBin" seems to be what is crashing my computer. (If I use any number of bytes other that 4 it seems to occasionaly crash). The one sticky point is that when using "peek" or "read", sometimes you get a string that is shorter than the number of bytes available to you. The only thing I can think of is that there is a embedded \0 character in the data stream which C is then reading as the end of the string. It would help to have a read/write that dealt with the "string" we provide as a buffer instead. I assume this is true because doing: socket.send("test\0test2"); only outputs "test". Alan -+- Code --- load("sockdefs.js"); function sendData(socketA, socketB) { var bRetVal = false; var buf; if(socketA.data_waiting) { var numRead = socketA.nread; if (numRead > 512) numRead = 512; buf = socketA.peek(numRead); if (numRead != buf.length) { numRead = buf.length; buf = socketA.recv(numRead + 1); // Not sure what we are skipping here, but it seems harmless? Maybe a zero? socketB.send(buf); } else { buf = socketA.recv(numRead); socketB.send(buf); } bRetVal = true; } return bRetVal; } try { if (argc < 2) { throw("No parameters passed."); }; var socket = new Socket(); if(!socket.bind()) { throw("!bind error " + socket.last_error + "\r\n"); exit(); } var addr=argv[0]; var port=argv[1]; if(!socket.connect(addr,port)) { throw("!connect error " + socket.last_error + "\r\n"); exit(); } while(socket.is_connected && client.socket.is_connected) { if (sendData(socket, client.socket)) continue; if (sendData(client.socket, socket)) continue; sleep(1); } } catch(E) { log("Caught error - " + E); exit(-1); } exit(0); --- þ Synchronet þ Holodeck One - bbs.holodeckone.com . 0