# Help translating C# socket code equivalent Ruby socket code

**URL:** <https://www.ruby-forum.com/t/help-translating-c-socket-code-equivalent-ruby-socket-code/158971>\
**Category:** Ruby\
**Created:** [January 29, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/help-translating-c-socket-code-equivalent-ruby-socket-code/158971 "2009-01-29T22:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamaljeetsinghsaini](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kamaljeetsinghsaini](https://www.ruby-forum.com/u/kamaljeetsinghsaini)\
**Post date:** [January 29, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/help-translating-c-socket-code-equivalent-ruby-socket-code/158971/1 "2009-01-29T22:32:37Z")

</div>

Possible to help in translating the following C# socket code to Ruby  
socket code please. What specific socket code lines needs to do  
following task.

using System.Net.Sockets;  
Socket clientSock;

clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,  
ProtocolType.Tcp);

receivedBytesLen = clientSock.Receive(Recievbuf, bufoffset, packetsize,  
0);

int fileNameLen = BitConverter.ToChar(Recievbuf, 0);

string fileName = “image1.text”;[//Encoding.ASCII.GetString](https://Encoding.ASCII.GetString)(Recievbuf, 4,  
fileNameLen);

// MessageBox.Show(“Client:{0} connected & File {1} started received.” +  
clientSock.RemoteEndPoint + fileName);

bWrite = new BinaryWriter(File.Open(receivedPath + fileName,  
FileMode.Append));

[//bWrite.Write](https://bWrite.Write)(Recievbuf, (int)(352 \* 240 \* 2 - test),  
receivedBytesLen);

bWrite.Write(Recievbuf, bufoffset, receivedBytesLen);

// MessageBox.Show(“File: {0} received & saved at path: {1}” + fileName

- receivedPath);

if (receivedBytesLen != -1)

{

bufoffset += receivedBytesLen;

leftover = toRecv - bufoffset;

if (leftover \< packetsize)

{

packetsize = leftover;

}

}

---

<div class="post-metadata">

**Author:** ![kamaljeetsinghsaini](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kamaljeetsinghsaini](https://www.ruby-forum.com/u/kamaljeetsinghsaini)\
**Post date:** [January 30, 2009, 2:22am UTC](https://www.ruby-forum.com/t/help-translating-c-socket-code-equivalent-ruby-socket-code/158971/2 "2009-01-30T02:22:32Z")

</div>

On Jan 29, 4:30 pm, Kamaljeet S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Possible to help in translating the following C# socket code to Ruby  
> socket code please. What specific socket code lines needs to do  
> following task.

‘help’ != ‘do it for you’

If you understand the C# code, take a stab at it in Ruby. If you get  
stuck, you’re more likely to get help. If you don’t understand the C#  
code, try asking in a different forum. If you don’t understand C#,  
Ruby, or socket programming then good luck!

---

<div class="post-metadata">

**Author:** ![kamaljeetsinghsaini](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/53a042/32.png) [@kamaljeetsinghsaini](https://www.ruby-forum.com/u/kamaljeetsinghsaini)\
**Post date:** [January 30, 2009, 5:04am UTC](https://www.ruby-forum.com/t/help-translating-c-socket-code-equivalent-ruby-socket-code/158971/3 "2009-01-30T05:04:44Z")

</div>

The C# code make sense and understandable but the basic ruby socket  
lines those could be quite generic to do this, if those are handy to  
someone in the forum can save some time and we can try those and  
manipulate as needed.

Thatâ€™s what im look for. If that input we can receive please.
